Project Introduction

The Ticket Booking System is designed to facilitate the organization and management of events, including ticket sales, bookings, and user interactions. Built using ASP.NET and SQL Server, this application provides a comprehensive platform for users to create and manage events, purchase tickets, and receive notifications about their bookings. The system also allows administrators to track payments, manage support tickets, and gather feedback, ensuring a smooth experience for both event organizers and attendees.

Project Objectives

  • To create a secure user authentication system for managing user accounts and roles.
  • To enable users to create and manage events, including details such as title, description, and venue.
  • To facilitate ticket sales for events, including pricing and availability management.
  • To manage user bookings, including tracking quantities and total amounts.
  • To implement a payment processing system for completed bookings.
  • To provide notifications to users regarding their bookings and event updates.
  • To generate reports on user activities, bookings, and event performance.
  • To manage support tickets for user inquiries and issues.
  • To collect user feedback to improve the overall system and user experience.

Project Modules

  1. User Management Module: Handles user registration, login, and role management.
  2. Event Management Module: Allows users to create, edit, and delete events.
  3. Ticket Management Module: Manages ticket creation, pricing, and availability for events.
  4. Booking Management Module: Facilitates user bookings and tracks booking details.
  5. Payment Management Module: Handles payment processing for bookings and tracks payment statuses.
  6. Notification Module: Sends notifications to users regarding bookings and event updates.
  7. Report Generation Module: Generates reports on bookings, payments, and user activities.
  8. Support Ticket Module: Manages user support tickets and tracks their status.
  9. Feedback Module: Collects and manages user feedback to enhance the system.

SQL Server Database Tables


-- Create Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(256) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
RoleId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Create Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- Create Events Table
CREATE TABLE Events (
EventId INT PRIMARY KEY IDENTITY(1,1),
Title NVARCHAR(100) NOT NULL,
Description NVARCHAR(MAX),
EventDate DATETIME NOT NULL,
Venue NVARCHAR(100) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create Tickets Table
CREATE TABLE Tickets (
TicketId INT PRIMARY KEY IDENTITY(1,1),
EventId INT,
Price DECIMAL(18, 2) NOT NULL,
TotalAvailable INT NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (EventId) REFERENCES Events(EventId)
);
-- Create Bookings Table
CREATE TABLE Bookings (
BookingId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
TicketId INT,
BookingDate DATETIME DEFAULT GETDATE(),
Quantity INT NOT NULL,
TotalAmount DECIMAL(18, 2) NOT NULL,
Status NVARCHAR(50) NOT NULL, -- e.g., Confirmed, Cancelled
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (TicketId) REFERENCES Tickets(TicketId)
);
-- Create Payments Table
CREATE TABLE Payments (
PaymentId INT PRIMARY KEY IDENTITY(1,1),
BookingId INT,
PaymentDate DATETIME DEFAULT GETDATE(),
Amount DECIMAL(18, 2) NOT NULL,
PaymentMethod NVARCHAR(50) NOT NULL, -- e.g., Credit Card, PayPal
Status NVARCHAR(50) NOT NULL, -- e.g., Completed, Failed
FOREIGN KEY (BookingId) REFERENCES Bookings(BookingId)
);
-- Create Notifications Table
CREATE TABLE Notifications (
NotificationId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Message NVARCHAR(256) NOT NULL,
IsRead BIT DEFAULT 0,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Reports Table
CREATE TABLE Reports (
ReportId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
ReportDate DATETIME DEFAULT GETDATE(),
Description NVARCHAR(MAX),
Status NVARCHAR(50) NOT NULL, -- e.g., Open, Closed
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create SupportTickets Table
CREATE TABLE SupportTickets (
SupportTicketId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
Subject NVARCHAR(100) NOT NULL,
Message NVARCHAR(MAX) NOT NULL,
Status NVARCHAR(50) NOT NULL, -- e.g., Open, Resolved
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Feedback Table
CREATE TABLE Feedback (
FeedbackId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Comments NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);

Explanation of the Tables

Users: Stores user information, including username, password hash, email, and role.

Roles: Defines user roles (e.g., Admin, Customer).

Events: Contains event details, including title, description, date, and venue.

Tickets: Manages ticket information for events, including price and availability.

Bookings: Tracks user bookings for tickets, including booking date, quantity, total amount, and status.

Payments: Stores payment information related to bookings, including payment date, amount, method, and status.

Notifications: Manages notifications for users, such as alerts for bookings or events.

Reports: Stores reports submitted by users, including description and status.

SupportTickets: Manages support tickets raised by users, including subject, message, and status.

Feedback: Stores feedback from users regarding the platform or services.

To create models and repositories using ADO.NET for your Online Ticket Booking System based on the provided SQL Server queries

We will follow these steps:

Create Models

Define C# classes that represent the database tables.


//Models/User.cs
public class User
{
public int UserId { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
public string Email { get; set; }
public int RoleId { get; set; }
public DateTime CreatedAt { get; set; }
}
//Models/Role.cs
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
//Models/Event.cs
public class Event
{
public int EventId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime EventDate { get; set; }
public string Venue { get; set; }
public DateTime CreatedAt { get; set; }
}
//Models/Ticket.cs
public class Ticket
{
public int TicketId { get; set; }
public int EventId { get; set; }
public decimal Price { get; set; }
public int TotalAvailable { get; set; }
public DateTime CreatedAt { get; set; }
}
//Models/Booking.cs
public class Booking
{
public int BookingId { get; set; }
public int UserId { get; set; }
public int TicketId { get; set; }
public DateTime BookingDate { get; set; }
public int Quantity { get; set; }
public decimal TotalAmount { get; set; }
public string Status { get; set; }
}
//Models/Payment.cs
public class Payment
{
public int PaymentId { get; set; }
public int BookingId { get; set; }
public DateTime PaymentDate { get; set; }
public decimal Amount { get; set; }
public string PaymentMethod { get; set; }
public string Status { get; set; }
}
//Models/Notification.cs
public class Notification
{
public int NotificationId { get; set; }
public int UserId { get; set; }
public string Message { get; set; }
public bool IsRead { get; set; }
public DateTime CreatedAt { get; set; }
}
//Models/Report.cs
public class Report
{
public int ReportId { get; set; }
public int UserId { get; set; }
public DateTime ReportDate { get; set; }
public string Description { get; set; }
public string Status { get; set; }
}
//Models/SupportTicket.cs
public class SupportTicket
{
public int SupportTicketId { get; set; }
public int UserId { get; set; }
public DateTime CreatedAt { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public string Status { get; set; }
}
//Models/Feedback.cs
public class Feedback
{
public int FeedbackId { get; set; }
public int UserId { get; set; }
public string Comments { get; set; }
public DateTime CreatedAt { get; set; }
}

Create Repositories

Now, let's create repository classes for each model using ADO.NET.

Repositories/UserRepository.cs

Create Repository with complete CRUD operation

Below are the complete implementations of the repository classes for each model in your Online Ticket Booking System, including full CRUD (Create, Read, Update, Delete) operations using ADO.NET.

UserRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class UserRepository
{
private readonly string _connectionString;
public UserRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddUser (User user)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Users (Username, PasswordHash, Email, RoleId) VALUES (@Username, @PasswordHash, @Email, @RoleId)", connection);
command.Parameters.AddWithValue("@Username", user.Username);
command.Parameters.AddWithValue("@PasswordHash", user.PasswordHash);
command.Parameters.AddWithValue("@Email", user.Email);
command.Parameters.AddWithValue("@RoleId", user.RoleId);
connection.Open();
command.ExecuteNonQuery();
}
}
public User GetUser ById(int userId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Users WHERE UserId = @User Id", connection);
command.Parameters.AddWithValue("@User Id", userId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new User
{
UserId = (int)reader["User Id"],
Username = reader["Username"].ToString(),
PasswordHash = reader["PasswordHash"].ToString(),
Email = reader["Email"].ToString(),
RoleId = (int)reader["RoleId"],
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return null;
}
public List<User> GetAllUsers()
{
var users = new List<User>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Users", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
users.Add(new User
{
UserId = (int)reader["User Id"],
Username = reader["Username"].ToString(),
PasswordHash = reader["PasswordHash"].ToString(),
Email = reader["Email"].ToString(),
RoleId = (int)reader["RoleId"],
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return users;
}
public void UpdateUser (User user)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Users SET Username = @Username, PasswordHash = @PasswordHash, Email = @Email, RoleId = @RoleId WHERE UserId = @User Id", connection);
command.Parameters.AddWithValue("@User Id", user.UserId);
command.Parameters.AddWithValue("@Username", user.Username);
command.Parameters.AddWithValue("@PasswordHash", user.PasswordHash);
command.Parameters.AddWithValue("@Email", user.Email);
command.Parameters.AddWithValue("@RoleId", user.RoleId);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteUser (int userId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Users WHERE UserId = @User Id", connection);
command.Parameters.AddWithValue("@User Id", userId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

RoleRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class RoleRepository
{
private readonly string _connectionString;
public RoleRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddRole(Role role)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Roles (RoleName) VALUES (@RoleName)", connection);
command.Parameters.AddWithValue("@RoleName", role.RoleName);
connection.Open();
command.ExecuteNonQuery();
}
}
public Role GetRoleById(int roleId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Roles WHERE RoleId = @RoleId", connection);
command.Parameters.AddWithValue("@RoleId", roleId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Role
{
RoleId = (int)reader["RoleId"],
RoleName = reader["RoleName"].ToString()
};
}
}
}
return null;
}
public List<Role> GetAllRoles()
{
var roles = new List<Role>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Roles", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
roles.Add(new Role
{
RoleId = (int)reader["RoleId"],
RoleName = reader["RoleName"].ToString()
});
}
}
}
return roles;
}
public void UpdateRole(Role role)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Roles SET RoleName = @RoleName WHERE RoleId = @RoleId", connection);
command.Parameters.AddWithValue("@RoleId", role.RoleId);
command.Parameters.AddWithValue("@RoleName", role.RoleName);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteRole(int roleId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Roles WHERE RoleId = @RoleId", connection);
command.Parameters.AddWithValue("@RoleId", roleId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

EventRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class EventRepository
{
private readonly string _connectionString;
public EventRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddEvent(Event eventItem)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Events (Title, Description, EventDate, Venue) VALUES (@Title, @Description, @EventDate, @Venue)", connection);
command.Parameters.AddWithValue("@Title", eventItem.Title);
command.Parameters.AddWithValue("@Description", eventItem.Description);
command.Parameters.AddWithValue("@EventDate", eventItem.EventDate);
command.Parameters.AddWithValue("@Venue", eventItem.Venue);
connection.Open ();
command.ExecuteNonQuery();
}
}
public Event GetEventById(int eventId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Events WHERE EventId = @EventId", connection);
command.Parameters.AddWithValue("@EventId", eventId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Event
{
EventId = (int)reader["EventId"],
Title = reader["Title"].ToString(),
Description = reader["Description"].ToString(),
EventDate = (DateTime)reader["EventDate"],
Venue = reader["Venue"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return null;
}
public List<Event> GetAllEvents()
{
var events = new List<Event>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Events", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
events.Add(new Event
{
EventId = (int)reader["EventId"],
Title = reader["Title"].ToString(),
Description = reader["Description"].ToString(),
EventDate = (DateTime)reader["EventDate"],
Venue = reader["Venue"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return events;
}
public void UpdateEvent(Event eventItem)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Events SET Title = @Title, Description = @Description, EventDate = @EventDate, Venue = @Venue WHERE EventId = @EventId", connection);
command.Parameters.AddWithValue("@EventId", eventItem.EventId);
command.Parameters.AddWithValue("@Title", eventItem.Title);
command.Parameters.AddWithValue("@Description", eventItem.Description);
command.Parameters.AddWithValue("@EventDate", eventItem.EventDate);
command.Parameters.AddWithValue("@Venue", eventItem.Venue);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteEvent(int eventId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Events WHERE EventId = @EventId", connection);
command.Parameters.AddWithValue("@EventId", eventId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

TicketRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class TicketRepository
{
private readonly string _connectionString;
public TicketRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddTicket(Ticket ticket)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Tickets (EventId, Price, TotalAvailable) VALUES (@EventId, @Price, @TotalAvailable)", connection);
command.Parameters.AddWithValue("@EventId", ticket.EventId);
command.Parameters.AddWithValue("@Price", ticket.Price);
command.Parameters.AddWithValue("@TotalAvailable", ticket.TotalAvailable);
connection.Open();
command.ExecuteNonQuery();
}
}
public Ticket GetTicketById(int ticketId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Tickets WHERE TicketId = @TicketId", connection);
command.Parameters.AddWithValue("@TicketId", ticketId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Ticket
{
TicketId = (int)reader["TicketId"],
EventId = (int)reader["EventId"],
Price = (decimal)reader["Price"],
TotalAvailable = (int)reader["TotalAvailable"],
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return null;
}
public List<Ticket> GetAllTickets()
{
var tickets = new List<Ticket>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Tickets", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
tickets.Add(new Ticket
{
TicketId = (int)reader["TicketId"],
EventId = ( int)reader["EventId"],
Price = (decimal)reader["Price"],
TotalAvailable = (int)reader["TotalAvailable"],
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return tickets;
}
public void UpdateTicket(Ticket ticket)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Tickets SET EventId = @EventId, Price = @Price, TotalAvailable = @TotalAvailable WHERE TicketId = @TicketId", connection);
command.Parameters.AddWithValue("@TicketId", ticket.TicketId);
command.Parameters.AddWithValue("@EventId", ticket.EventId);
command.Parameters.AddWithValue("@Price", ticket.Price);
command.Parameters.AddWithValue("@TotalAvailable", ticket.TotalAvailable);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteTicket(int ticketId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Tickets WHERE TicketId = @TicketId", connection);
command.Parameters.AddWithValue("@TicketId", ticketId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

BookingRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class BookingRepository
{
private readonly string _connectionString;
public BookingRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddBooking(Booking booking)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Bookings (User Id, TicketId, BookingDate, Quantity, TotalAmount, Status) VALUES (@User Id, @TicketId, @BookingDate, @Quantity, @TotalAmount, @Status)", connection);
command.Parameters.AddWithValue("@User Id", booking.UserId);
command.Parameters.AddWithValue("@TicketId", booking.TicketId);
command.Parameters.AddWithValue("@BookingDate", booking.BookingDate);
command.Parameters.AddWithValue("@Quantity", booking.Quantity);
command.Parameters.AddWithValue("@TotalAmount", booking.TotalAmount);
command.Parameters.AddWithValue("@Status", booking.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public Booking GetBookingById(int bookingId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Bookings WHERE BookingId = @BookingId", connection);
command.Parameters.AddWithValue("@BookingId", bookingId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Booking
{
BookingId = (int)reader["BookingId"],
UserId = (int)reader["User Id"],
TicketId = (int)reader["TicketId"],
BookingDate = (DateTime)reader["BookingDate"],
Quantity = (int)reader["Quantity"],
TotalAmount = (decimal)reader["TotalAmount"],
Status = reader["Status"].ToString()
};
}
}
}
return null;
}
public List<Booking> GetAllBookings()
{
var bookings = new List<Booking>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Bookings", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
bookings.Add(new Booking
{
BookingId = (int)reader["BookingId"],
UserId = (int)reader["User Id"],
TicketId = (int)reader["TicketId"],
BookingDate = (DateTime)reader["BookingDate"],
Quantity = (int)reader["Quantity"],
TotalAmount = (decimal)reader["TotalAmount"],
Status = reader["Status"].ToString()
});
}
}
}
return bookings;
}
public void UpdateBooking(Booking booking)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Bookings SET UserId = @User Id, TicketId = @TicketId, BookingDate = @BookingDate, Quantity = @Quantity, TotalAmount = @TotalAmount, Status = @Status WHERE BookingId = @BookingId", connection);
command.Parameters.AddWithValue("@BookingId", booking.BookingId);
command.Parameters.AddWithValue("@User Id", booking.UserId);
command.Parameters.AddWithValue("@TicketId", booking.TicketId);
command.Parameters.AddWithValue("@BookingDate", booking.BookingDate);
command.Parameters.Add WithValue("@Quantity", booking.Quantity);
command.Parameters.AddWithValue("@TotalAmount", booking.TotalAmount);
command.Parameters.AddWithValue("@Status", booking.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteBooking(int bookingId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Bookings WHERE BookingId = @BookingId", connection);
command.Parameters.AddWithValue("@BookingId", bookingId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

PaymentRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class PaymentRepository
{
private readonly string _connectionString;
public PaymentRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddPayment(Payment payment)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Payments (BookingId, PaymentDate, Amount, PaymentMethod, Status) VALUES (@BookingId, @PaymentDate, @Amount, @PaymentMethod, @Status)", connection);
command.Parameters.AddWithValue("@BookingId", payment.BookingId);
command.Parameters.AddWithValue("@PaymentDate", payment.PaymentDate);
command.Parameters.AddWithValue("@Amount", payment.Amount);
command.Parameters.AddWithValue("@PaymentMethod", payment.PaymentMethod);
command.Parameters.AddWithValue("@Status", payment.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public Payment GetPaymentById(int paymentId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Payments WHERE PaymentId = @PaymentId", connection);
command.Parameters.AddWithValue("@PaymentId", paymentId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Payment
{
PaymentId = (int)reader["PaymentId"],
BookingId = (int)reader["BookingId"],
PaymentDate = (DateTime)reader["PaymentDate"],
Amount = (decimal)reader["Amount"],
PaymentMethod = reader["PaymentMethod"].ToString(),
Status = reader["Status"].ToString()
};
}
}
}
return null;
}
public List<Payment> GetAllPayments()
{
var payments = new List<Payment>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Payments", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
payments.Add(new Payment
{
PaymentId = (int)reader["PaymentId"],
BookingId = (int)reader["BookingId"],
PaymentDate = (DateTime)reader["PaymentDate"],
Amount = (decimal)reader["Amount"],
PaymentMethod = reader["PaymentMethod"].ToString(),
Status = reader["Status"].ToString()
});
}
}
}
return payments;
}
public void UpdatePayment(Payment payment)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Payments SET BookingId = @BookingId, PaymentDate = @PaymentDate, Amount = @Amount, PaymentMethod = @PaymentMethod, Status = @Status WHERE PaymentId = @PaymentId", connection);
command.Parameters.AddWithValue("@PaymentId", payment.PaymentId);
command.Parameters.AddWithValue("@BookingId", payment.BookingId);
command.Parameters.AddWithValue("@PaymentDate", payment.PaymentDate);
command.Parameters.AddWithValue("@Amount", payment.Amount);
command.Parameters.AddWithValue("@PaymentMethod", payment.PaymentMethod);
command.Parameters.AddWithValue("@Status", payment.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeletePayment(int paymentId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Payments WHERE PaymentId = @PaymentId", connection);
command.Parameters.AddWithValue("@PaymentId", paymentId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

NotificationRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class NotificationRepository
{
private readonly string _connectionString;
public NotificationRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddNotification(Notification notification)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Notifications (User Id, Message, IsRead) VALUES (@User Id, @Message, @IsRead)", connection);
command.Parameters.AddWithValue("@User Id", notification.UserId);
command.Parameters.AddWithValue("@Message", notification.Message);
command.Parameters.AddWithValue("@IsRead", notification.IsRead);
connection.Open();
command.ExecuteNonQuery();
}
}
public Notification GetNotificationById(int notificationId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Notifications WHERE NotificationId = @NotificationId", connection);
command.Parameters.AddWithValue("@NotificationId", notificationId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Notification
{
NotificationId = (int)reader["NotificationId"],
UserId = (int)reader["User Id"],
Message = reader["Message"].ToString(),
IsRead = (bool)reader["IsRead"],
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return null;
}
public List<Notification> GetAllNotifications()
{
var notifications = new List<Notification>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Notifications", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
notifications.Add(new Notification
{
NotificationId = (int)reader["NotificationId"],
UserId = (int)reader["User Id"],
Message = reader["Message"].ToString(),
IsRead = (bool)reader["IsRead"],
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return notifications;
}
public void UpdateNotification(Notification notification)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Notifications SET UserId = @User Id, Message = @Message, IsRead = @IsRead WHERE NotificationId = @NotificationId", connection);
command.Parameters.AddWithValue("@NotificationId", notification.NotificationId);
command.Parameters.AddWithValue("@User Id", notification.UserId);
command.Parameters.AddWithValue("@Message", notification.Message);
command.Parameters.AddWithValue("@IsRead", notification.IsRead);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteNotification(int notificationId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Notifications WHERE NotificationId = @NotificationId", connection);
command.Parameters.AddWithValue("@NotificationId", notificationId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

ReportRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class ReportRepository
{
private readonly string _connectionString;
public ReportRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddReport(Report report)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Reports (User Id, ReportDate, Description, Status) VALUES (@User Id, @ReportDate, @Description, @Status)", connection);
command.Parameters.AddWithValue("@User Id", report.UserId);
command.Parameters.AddWithValue("@ReportDate", report.ReportDate);
command.Parameters.AddWithValue("@Description", report.Description);
command.Parameters.AddWithValue("@Status", report.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public Report GetReportById(int reportId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Reports WHERE ReportId = @ReportId", connection);
command.Parameters.AddWithValue("@ReportId", reportId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Report
{
ReportId = (int)reader["ReportId"],
UserId = (int)reader["User Id"],
ReportDate = (DateTime)reader["ReportDate"],
Description = reader["Description"].ToString(),
Status = reader["Status"].ToString()
};
}
}
}
return null;
}
public List<Report> GetAllReports()
{
var reports = new List<Report>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand(" SELECT * FROM Reports", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
reports.Add(new Report
{
ReportId = (int)reader["ReportId"],
UserId = (int)reader["User Id"],
ReportDate = (DateTime)reader["ReportDate"],
Description = reader["Description"].ToString(),
Status = reader["Status"].ToString()
});
}
}
}
return reports;
}
public void UpdateReport(Report report)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Reports SET UserId = @User Id, ReportDate = @ReportDate, Description = @Description, Status = @Status WHERE ReportId = @ReportId", connection);
command.Parameters.AddWithValue("@ReportId", report.ReportId);
command.Parameters.AddWithValue("@User Id", report.UserId);
command.Parameters.AddWithValue("@ReportDate", report.ReportDate);
command.Parameters.AddWithValue("@Description", report.Description);
command.Parameters.AddWithValue("@Status", report.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteReport(int reportId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Reports WHERE ReportId = @ReportId", connection);
command.Parameters.AddWithValue("@ReportId", reportId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

SupportTicketRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class SupportTicketRepository
{
private readonly string _connectionString;
public SupportTicketRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddSupportTicket(SupportTicket supportTicket)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO SupportTickets (User Id, Subject, Message, Status) VALUES (@User Id, @Subject, @Message, @Status)", connection);
command.Parameters.AddWithValue("@User Id", supportTicket.UserId);
command.Parameters.AddWithValue("@Subject", supportTicket.Subject);
command.Parameters.AddWithValue("@Message", supportTicket.Message);
command.Parameters.AddWithValue("@Status", supportTicket.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public SupportTicket GetSupportTicketById(int supportTicketId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM SupportTickets WHERE SupportTicketId = @SupportTicketId", connection);
command.Parameters.AddWithValue("@SupportTicketId", supportTicketId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new SupportTicket
{
SupportTicketId = (int)reader["SupportTicketId"],
UserId = (int)reader["User Id"],
CreatedAt = (DateTime)reader["CreatedAt"],
Subject = reader["Subject"].ToString(),
Message = reader["Message"].ToString(),
Status = reader["Status"].ToString()
};
}
}
}
return null;
}
public List<SupportTicket> GetAllSupportTickets()
{
var supportTickets = new List<SupportTicket>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM SupportTickets", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
supportTickets.Add(new SupportTicket
{
SupportTicketId = (int)reader["SupportTicketId"],
UserId = (int)reader["User Id"],
CreatedAt = (DateTime)reader["CreatedAt"],
Subject = reader["Subject"].ToString(),
Message = reader["Message"].ToString(),
Status = reader["Status"].ToString()
});
}
}
}
return supportTickets;
}
public void UpdateSupportTicket(SupportTicket supportTicket)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE SupportTickets SET UserId = @User Id, Subject = @Subject, Message = @Message, Status = @Status WHERE SupportTicketId = @SupportTicketId", connection);
command.Parameters.AddWithValue("@SupportTicketId", supportTicket.SupportTicketId);
command.Parameters.AddWithValue("@User Id", supportTicket.UserId);
command.Parameters.AddWithValue("@Subject", supportTicket.Subject);
command.Parameters.AddWithValue("@Message", supportTicket.Message);
command.Parameters.AddWithValue("@Status", supportTicket.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteSupportTicket(int supportTicketId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM SupportTickets WHERE SupportTicketId = @SupportTicketId", connection);
command.Parameters.AddWithValue("@SupportTicketId", supportTicketId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

FeedbackRepository.cs


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class FeedbackRepository
{
private readonly string _connectionString;
public FeedbackRepository(string connectionString)
{
_connectionString = connectionString;
}
public void AddFeedback(Feedback feedback)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Feedback (User Id, Comments) VALUES (@User Id, @Comments)", connection);
command.Parameters.AddWithValue("@User Id", feedback.UserId);
command.Parameters.AddWithValue("@Comments", feedback.Comments);
connection.Open();
command.ExecuteNonQuery();
}
}
public Feedback GetFeedbackById(int feedbackId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Feedback WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedbackId);
connection.Open();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
return new Feedback
{
FeedbackId = (int)reader["FeedbackId"],
UserId = (int)reader["User Id"],
Comments = reader["Comments"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return null;
}
public List<Feedback> GetAllFeedbacks()
{
var feedbacks = new List<Feedback>();
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("SELECT * FROM Feedback", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
feedbacks.Add(new Feedback
{
FeedbackId = (int)reader["FeedbackId"],
UserId = (int)reader["User Id"],
Comments = reader["Comments"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return feedbacks;
}
public void UpdateFeedback(Feedback feedback)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Feedback SET UserId = @User Id, Comments = @Comments WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedback.FeedbackId);
command.Parameters.AddWithValue("@User Id", feedback.UserId);
command.Parameters.AddWithValue("@Comments", feedback.Comments);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteFeedback(int feedbackId)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("DELETE FROM Feedback WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedbackId);
connection.Open();
command.ExecuteNonQuery();
}
}
}

Each repository class now includes complete CRUD operations for its respective model. This structure allows for easy management of data in your Online Ticket Booking System, ensuring that you can create, read, update, and delete records as needed. You can further enhance these repositories with additional methods for specific queries or business logic as required.

Now create controller for each repository

Below are the controller implementations for each repository in your Online Ticket Booking System. Each controller will handle HTTP requests and interact with the corresponding repository to perform CRUD operations.

UserController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class UserController : Controller
{
private readonly UserRepository _userRepository;
public UserController(UserRepository userRepository)
{
_userRepository = userRepository;
}
[HttpGet]
public IActionResult Index()
{
var users = _userRepository.GetAllUsers();
return View(users);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(User user)
{
if (ModelState.IsValid)
{
_userRepository.AddUser (user);
return RedirectToAction("Index");
}
return View(user);
}
[HttpGet]
public IActionResult Edit(int id)
{
var user = _userRepository.GetUser ById(id);
return View(user);
}
[HttpPost]
public IActionResult Edit(User user)
{
if (ModelState.IsValid)
{
_userRepository.UpdateUser (user);
return RedirectToAction("Index");
}
return View(user);
}
[HttpGet]
public IActionResult Delete(int id)
{
_userRepository.DeleteUser (id);
return RedirectToAction("Index");
}
}

RoleController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class RoleController : Controller
{
private readonly RoleRepository _roleRepository;
public RoleController(RoleRepository roleRepository)
{
_roleRepository = roleRepository;
}
[HttpGet]
public IActionResult Index()
{
var roles = _roleRepository.GetAllRoles();
return View(roles);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Role role)
{
if (ModelState.IsValid)
{
_roleRepository.AddRole(role);
return RedirectToAction("Index");
}
return View(role);
}
[HttpGet]
public IActionResult Edit(int id)
{
var role = _roleRepository.GetRoleById(id);
return View(role);
}
[HttpPost]
public IActionResult Edit(Role role)
{
if (ModelState.IsValid)
{
_roleRepository.UpdateRole(role);
return RedirectToAction("Index");
}
return View(role);
}
[HttpGet]
public IActionResult Delete(int id)
{
_roleRepository.DeleteRole(id);
return RedirectToAction("Index");
}
}

EventController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class EventController : Controller
{
private readonly EventRepository _eventRepository;
public EventController(EventRepository eventRepository)
{
_eventRepository = eventRepository;
}
[HttpGet]
public IActionResult Index()
{
var events = _eventRepository.GetAllEvents();
return View(events);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Event eventItem)
{
if (ModelState.IsValid)
{
_eventRepository.AddEvent(eventItem);
return RedirectToAction("Index");
}
return View(eventItem);
}
[HttpGet]
public IActionResult Edit(int id)
{
var eventItem = _eventRepository.GetEventById(id);
return View(eventItem);
}
[HttpPost]
public IActionResult Edit(Event eventItem)
{
if (ModelState.IsValid)
{
_eventRepository.UpdateEvent(eventItem);
return RedirectToAction("Index");
}
return View(eventItem);
}
[HttpGet]
public IActionResult Delete(int id)
{
_eventRepository.DeleteEvent(id);
return RedirectToAction("Index");
}
}

TicketController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class TicketController : Controller
{
private readonly TicketRepository _ticketRepository;
public TicketController(TicketRepository ticketRepository)
{
_ticketRepository = ticketRepository;
}
[HttpGet]
public IActionResult Index()
{
var tickets = _ticketRepository.GetAllTickets();
return View(tickets);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Ticket ticket)
{
if (ModelState.IsValid)
{
_ticketRepository.AddTicket(ticket);
return RedirectToAction("Index");
}
return View(ticket);
}
[HttpGet]
public IActionResult Edit(int id)
{
var ticket = _ticketRepository.GetTicketById(id);
return View(ticket);
}
[HttpPost]
public IActionResult Edit(Ticket ticket)
{
if (ModelState.IsValid)
{
_ticketRepository.UpdateTicket(ticket);
return RedirectToAction("Index");
}
return View(ticket);
}
[HttpGet]
public IActionResult Delete(int id)
{
_ticketRepository.DeleteTicket(id);
return RedirectToAction("Index");
}
}

BookingController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class BookingController : Controller
{
private readonly BookingRepository _bookingRepository;
public BookingController(BookingRepository bookingRepository)
{
_bookingRepository = bookingRepository;
}
[HttpGet]
public IActionResult Index()
{
var bookings = _bookingRepository.GetAllBookings();
return View(bookings);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Booking booking)
{
if (ModelState.IsValid)
{
_bookingRepository.AddBooking(booking);
return RedirectToAction("Index");
}
return View(booking);
}
[HttpGet]
public IActionResult Edit(int id)
{
var booking = _bookingRepository.GetBookingById(id);
return View(booking);
}
[HttpPost]
public IActionResult Edit(Booking booking)
{
if (ModelState.IsValid)
{
_bookingRepository.UpdateBooking(booking);
return RedirectToAction("Index");
}
return View(booking);
}
[HttpGet]
public IActionResult Delete(int id)
{
_bookingRepository.DeleteBooking(id);
return RedirectToAction("Index");
}
}

PaymentController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class PaymentController : Controller
{
private readonly PaymentRepository _paymentRepository;
public PaymentController(PaymentRepository paymentRepository)
{
_paymentRepository = paymentRepository;
}
[HttpGet]
public IActionResult Index()
{
var payments = _paymentRepository.GetAllPayments();
return View(payments);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Payment payment)
{
if (ModelState.IsValid)
{
_paymentRepository.AddPayment(payment);
return RedirectToAction("Index");
}
return View(payment);
}
[HttpGet]
public IActionResult Edit(int id)
{
var payment = _paymentRepository.GetPaymentById(id);
return View(payment);
}
[HttpPost]
public IActionResult Edit(Payment payment)
{
if (ModelState.IsValid)
{
_paymentRepository.UpdatePayment(payment);
return RedirectToAction("Index");
}
return View(payment);
}
[HttpGet]
public IActionResult Delete(int id)
{
_paymentRepository.DeletePayment(id);
return RedirectToAction("Index");
}
}

NotificationController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class NotificationController : Controller
{
private readonly NotificationRepository _notificationRepository;
public NotificationController(NotificationRepository notificationRepository)
{
_notificationRepository = notificationRepository;
}
[HttpGet]
public IActionResult Index()
{
var notifications = _notificationRepository.GetAllNotifications();
return View(notifications);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Notification notification)
{
if (ModelState.IsValid)
{
_notificationRepository.AddNotification(notification);
return RedirectToAction("Index");
}
return View(notification);
}
[HttpGet]
public IActionResult Edit(int id)
{
var notification = _notificationRepository.GetNotificationById(id);
return View(notification);
}
[HttpPost]
public IActionResult Edit(Notification notification)
{
if (ModelState.IsValid)
{
_notificationRepository.UpdateNotification(notification);
return RedirectToAction("Index");
}
return View(notification);
}
[HttpGet]
public IActionResult Delete(int id)
{
_notificationRepository.DeleteNotification(id);
return RedirectToAction("Index");
}
}

ReportController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class ReportController : Controller
{
private readonly ReportRepository _reportRepository;
public ReportController(ReportRepository reportRepository)
{
_reportRepository = reportRepository;
}
[HttpGet]
public IActionResult Index()
{
var reports = _reportRepository.GetAllReports();
return View(reports);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Report report)
{
if (ModelState.IsValid)
{
_reportRepository.AddReport(report);
return RedirectToAction("Index");
}
return View(report);
}
[HttpGet]
public IActionResult Edit(int id)
{
var report = _reportRepository.GetReportById(id);
return View(report);
}
[HttpPost]
public IActionResult Edit(Report report)
{
if (ModelState.IsValid)
{
_reportRepository.UpdateReport(report);
return RedirectToAction("Index");
}
return View(report);
}
[HttpGet]
public IActionResult Delete(int id)
{
_reportRepository.DeleteReport(id);
return RedirectToAction("Index");
}
}

SupportTicketController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class SupportTicketController : Controller
{
private readonly SupportTicketRepository _supportTicketRepository;
public SupportTicketController(SupportTicketRepository supportTicketRepository)
{
_supportTicketRepository = supportTicketRepository;
}
[HttpGet]
public IActionResult Index()
{
var supportTickets = _supportTicketRepository.GetAllSupportTickets();
return View(supportTickets);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(SupportTicket supportTicket)
{
if (ModelState.IsValid)
{
_supportTicketRepository.AddSupportTicket(supportTicket);
return RedirectToAction("Index");
}
return View(supportTicket);
}
[HttpGet]
public IActionResult Edit(int id)
{
var supportTicket = _supportTicketRepository.GetSupportTicketById(id);
return View(supportTicket );
}
[HttpPost]
public IActionResult Edit(SupportTicket supportTicket)
{
if (ModelState.IsValid)
{
_supportTicketRepository.UpdateSupportTicket(supportTicket);
return RedirectToAction("Index");
}
return View(supportTicket);
}
[HttpGet]
public IActionResult Delete(int id)
{
_supportTicketRepository.DeleteSupportTicket(id);
return RedirectToAction("Index");
}
}

FeedbackController.cs


using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
public class FeedbackController : Controller
{
private readonly FeedbackRepository _feedbackRepository;
public FeedbackController(FeedbackRepository feedbackRepository)
{
_feedbackRepository = feedbackRepository;
}
[HttpGet]
public IActionResult Index()
{
var feedbacks = _feedbackRepository.GetAllFeedbacks();
return View(feedbacks);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Feedback feedback)
{
if (ModelState.IsValid)
{
_feedbackRepository.AddFeedback(feedback);
return RedirectToAction("Index");
}
return View(feedback);
}
[HttpGet]
public IActionResult Edit(int id)
{
var feedback = _feedbackRepository.GetFeedbackById(id);
return View(feedback);
}
[HttpPost]
public IActionResult Edit(Feedback feedback)
{
if (ModelState.IsValid)
{
_feedbackRepository.UpdateFeedback(feedback);
return RedirectToAction("Index");
}
return View(feedback);
}
[HttpGet]
public IActionResult Delete(int id)
{
_feedbackRepository.DeleteFeedback(id);
return RedirectToAction("Index");
}
}

Each controller is designed to handle HTTP requests for its respective repository, providing methods for creating, reading, updating, and deleting records. This structure allows for a clean separation of concerns, making it easier to manage the application's logic and data flow. You can further enhance these controllers with additional features such as validation, error handling, and logging as needed.

Below are the Razor view files for each controller in your Online Ticket Booking System

Each view corresponds to the actions defined in the controllers, allowing you to create, read, update, and delete records for each entity.

User Views

Views/User/Index.cshtml


@model IEnumerable<User>
<h2>Users</h2>
<a href='@Url.Action("Create")'>Create New User</a>
<table>
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var user in Model)
{
<tr>
<td>@user.Username</td>
<td>@user.Email</td>
<td>@user.RoleId</td>
<td>
<a href='@Url.Action("Edit", new { id = user.UserId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = user.UserId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/User/Create.cshtml


@model User
<h2>Create User</h2>
<form asp-action="Create" method="post">
<label>Username:</label>
<input asp-for="Username" required />
<label>Password:</label>
<input asp-for="PasswordHash" type="password" required />
<label>Email:</label>
<input asp-for="Email" required />
<label>Role ID:</label>
<input asp-for="RoleId" required />
<button type="submit">Create</button>
</form>

Views/User/Edit.cshtml


@model User
<h2>Edit User</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="User Id" />
<label>Username:</label>
<input asp-for="Username" required />
<label>Password:</label>
<input asp-for="PasswordHash" type="password" />
<label>Email:</label>
<input asp-for="Email" required />
<label>Role ID:</label>
<input asp-for="RoleId" required />
<button type="submit">Update</button>
</form>

Role Views

Views/Role/Index.cshtml


@model IEnumerable<Role>
<h2>Roles</h2>
<a href='@Url.Action("Create")'>Create New Role</a>
<table>
<thead>
<tr>
<th>Role Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var role in Model)
{
<tr>
<td>@role.RoleName</td>
<td>
<a href='@Url.Action("Edit", new { id = role.RoleId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = role.RoleId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Role/Create.cshtml


@model Role
<h2>Create Role</h2>
<form asp-action="Create" method="post">
<label>Role Name:</label>
<input asp-for="RoleName" required />
<button type="submit">Create</button>
</form>

Views/Role/Edit.cshtml


@model Role
<h2>Edit Role</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="RoleId" />
<label>Role Name:</label>
<input asp-for="RoleName" required />
<button type="submit">Update</button>
</form>

Event Views

Views/Event/Index.cshtml


@model IEnumerable<Event>
<h2>Events</h2>
<a href='@Url.Action("Create")'>Create New Event</a>
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Event Date</th>
<th>Venue</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var eventItem in Model)
{
<tr>
<td>@eventItem.Title</td>
<td>@eventItem.Description</td>
<td>@eventItem.EventDate.ToShortDateString()</td>
<td>@eventItem.Venue</td>
<td>
<a href='@Url.Action("Edit", new { id = eventItem.EventId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = eventItem.EventId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Event/Create.cshtml


@model Event
<h2>Create Event</h2>
<form asp-action="Create" method="post">
<label>Title:</label>
<input asp-for="Title" required />
<label>Description:</label>
<textarea asp-for="Description" required></textarea>
<label>Event Date:</label>
<input asp-for="EventDate" type="datetime-local" required />
<label>Venue:</label>
<input asp-for="Venue" required />
<button type="submit">Create</button>
</form>

Views/Event/Edit.cshtml


@model Event
<h2>Edit Event</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="EventId" />
<label>Title:</label>
<input asp-for="Title" required />
<label>Description:</label>
<textarea asp-for="Description" required></textarea>
<label>Event Date:</label>
<input asp-for="EventDate" type="datetime-local" required />
<label>Venue:</label>
<input asp-for="Venue" required />
<button type="submit">Update</button>
</form>

Ticket Views

Views/Ticket/Index.cshtml


@model IEnumerable<Ticket>
<h2>Tickets</h2>
<a href='@Url.Action("Create")'>Create New Ticket</a>
<table>
<thead>
<tr>
<th>Event ID</th>
<th>Price</th>
<th>Total Available</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var ticket in Model)
{
<tr>
<td>@ticket.EventId</td>
<td>@ticket.Price</td>
<td>@ticket.TotalAvailable</td>
<td>
<a href='@Url.Action("Edit", new { id = ticket.TicketId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = ticket.TicketId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Ticket/Create.cshtml


@model Ticket
<h2>Create Ticket</h2>
<form asp-action="Create" method="post">
<label>Event ID:</label>
<input asp-for="EventId" required />
<label>Price:</label>
<input asp-for="Price" type="number" step="0.01" required />
<label>Total Available:</label>
<input asp-for="TotalAvailable" type="number" required />
<button type="submit">Create</button>
</form>

Views/Ticket/Edit.cshtml


@model Ticket
<h2>Edit Ticket</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="TicketId" />
<label>Event ID:</label>
<input asp-for="EventId" required />
<label>Price:</label>
<input asp-for="Price" type="number" step="0.01" required />
<label>Total Available:</label>
<input asp-for="TotalAvailable" type="number" required />
<button type="submit">Update</button>
</form>

Booking Views

Views/Booking/Index.cshtml


@model IEnumerable<Booking>
<h2>Bookings</h2>
<a href='@Url.Action("Create")'>Create New Booking</a>
<table>
<thead>
<tr>
<th>User ID</th>
<th>Ticket ID</th>
<th>Booking Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var booking in Model)
{
<tr>
<td>@booking.UserId</td>
<td>@booking.TicketId</td>
<td>@booking.BookingDate.ToShortDateString()</td>
<td>
<a href='@Url.Action("Edit", new { id = booking.BookingId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = booking.BookingId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Booking/Create.cshtml


@model Booking
<h2>Create Booking</h2>
<form asp-action="Create" method="post">
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Ticket ID:</label>
<input asp-for="TicketId" required />
<button type="submit">Create</button>
</form>

Views/Booking/Edit.cshtml


@model Booking
<h2>Edit Booking</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="BookingId" />
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Ticket ID:</label>
<input asp-for="TicketId" required />
<button type="submit">Update</button>
</form>

Payment Views

Views/Payment/Index.cshtml


@model IEnumerable<Payment>
<h2>Payments</h2>
<a href='@Url.Action("Create")'>Create New Payment</a>
<table>
<thead>
<tr>
<th>Booking ID</th>
<th>Amount</th>
<th>Payment Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var payment in Model)
{
<tr>
<td>@payment.BookingId</td>
<td>@payment.Amount</td>
<td>@payment.PaymentDate.ToShortDateString()</td>
<td>
<a href='@Url.Action("Edit", new { id = payment.PaymentId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = payment.PaymentId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Payment/Create.cshtml


@model Payment
<h2>Create Payment</h2>
<form asp-action="Create" method="post">
<label>Booking ID:</label>
<input asp-for="BookingId" required />
<label>Amount:</label>
<input asp-for="Amount" type="number" step="0.01" required />
<button type="submit">Create</button>
</form>

Views/Payment/Edit.cshtml


@model Payment
<h2>Edit Payment</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="PaymentId" />
<label>Booking ID:</label>
<input asp-for="Booking Id" required />
<label>Amount:</label>
<input asp-for="Amount" type="number" step="0.01" required />
<button type="submit">Update</button>
</form>

Notification Views

Views/Notification/Index.cshtml


@model IEnumerable<Notification>
<h2>Notifications</h2>
<a href='@Url.Action("Create")'>Create New Notification</a>
<table>
<thead>
<tr>
<th>Message</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var notification in Model)
{
<tr>
<td>@notification.Message</td>
<td>@notification.Date.ToShortDateString()</td>
<td>
<a href='@Url.Action("Edit", new { id = notification.NotificationId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = notification.NotificationId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Notification/Create.cshtml


@model Notification
<h2>Create Notification</h2>
<form asp-action="Create" method="post">
<label>Message:</label>
<textarea asp-for="Message" required></textarea>
<label>Date:</label>
<input asp-for="Date" type="date" required />
<button type="submit">Create</button>
</form>

Views/Notification/Edit.cshtml


@model Notification
<h2>Edit Notification</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="NotificationId" />
<label>Message:</label>
<textarea asp-for="Message" required></textarea>
<label>Date:</label>
<input asp-for="Date" type="date" required />
<button type="submit">Update</button>
</form>

Report Views

Views/Report/Index.cshtml


@model IEnumerable<Report>
<h2>Reports</h2>
<a href='@Url.Action("Create")'>Create New Report</a>
<table>
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var report in Model)
{
<tr>
<td>@report.Title</td>
<td>@report.Content</td>
<td>@report.Date.ToShortDateString()</td>
<td>
<a href='@Url.Action("Edit", new { id = report.ReportId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = report.ReportId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Report/Create.cshtml


@model Report
<h2>Create Report</h2>
<form asp-action="Create" method="post">
<label>Title:</label>
<input asp-for="Title" required />
<label>Content:</label>
<textarea asp-for="Content" required></textarea>
<label>Date:</label>
<input asp-for="Date" type="date" required />
<button type="submit">Create</button>
</form>

Views/Report/Edit.cshtml


@model Report
<h2>Edit Report</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="ReportId" />
<label>Title:</label>
<input asp-for="Title" required />
<label>Content:</label>
<textarea asp-for="Content" required></textarea>
<label>Date:</label>
<input asp-for="Date" type="date" required />
<button type="submit">Update</button>
</form>

Support Ticket Views

Views/SupportTicket/Index.cshtml


@model IEnumerable<SupportTicket>
<h2>Support Tickets</h2>
<a href='@Url.Action("Create")'>Create New Support Ticket</a>
<table>
<thead>
<tr>
<th>User ID</th>
<th>Issue</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var supportTicket in Model)
{
<tr>
<td>@supportTicket.UserId</td>
< td>@supportTicket.Issue</td>
<td>@supportTicket.Status</td>
<td>
<a href='@Url.Action("Edit", new { id = supportTicket.SupportTicketId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = supportTicket.SupportTicketId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/SupportTicket/Create.cshtml


@model SupportTicket
<h2>Create Support Ticket</h2>
<form asp-action="Create" method="post">
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Issue:</label>
<textarea asp-for="Issue" required></textarea>
<label>Status:</label>
<input asp-for="Status" required />
<button type="submit">Create</button>
</form>

Views/SupportTicket/Edit.cshtml


@model SupportTicket
<h2>Edit Support Ticket</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="SupportTicketId" />
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Issue:</label>
<textarea asp-for="Issue" required></textarea>
<label>Status:</label>
<input asp-for="Status" required />
<button type="submit">Update</button>
</form>

Feedback Views

Views/Feedback/Index.cshtml


@model IEnumerable<Feedback>
<h2>Feedbacks</h2>
<a href='@Url.Action("Create")'>Create New Feedback</a>
<table>
<thead>
<tr>
<th>User ID</th>
<th>Comments</th>
<th>Rating</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var feedback in Model)
{
<tr>
<td>@feedback.UserId</td>
<td>@feedback.Comments</td>
<td>@feedback.Rating</td>
<td>
<a href='@Url.Action("Edit", new { id = feedback.FeedbackId })'>Edit</a> |
<a href='@Url.Action("Delete", new { id = feedback.FeedbackId })'>Delete</a>
</td>
</tr>
}
</tbody>
</table>

Views/Feedback/Create.cshtml


@model Feedback
<h2>Create Feedback</h2>
<form asp-action="Create" method="post">
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Comments:</label>
<textarea asp-for="Comments" required></textarea>
<label>Rating:</label>
<input asp-for="Rating" type="number" min="1" max="5" required />
<button type="submit">Create</button>
</form>

Views/Feedback/Edit.cshtml


@model Feedback
<h2>Edit Feedback</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="FeedbackId" />
<label>User ID:</label>
<input asp-for="User Id" required />
<label>Comments:</label>
<textarea asp-for="Comments" required></textarea>
<label>Rating:</label>
<input asp-for="Rating" type="number" min="1" max="5" required />
<button type="submit">Update</button>
</form>

These Razor view files provide a user interface for managing users, roles, events, tickets, bookings, payments, notifications, reports, support tickets, and feedback in your Online Ticket Booking System. Each view is designed to facilitate the corresponding CRUD operations defined in the controllers, ensuring a seamless experience for users interacting with the application. You can further enhance these views with styling, client-side validation, and additional features as needed.

To create a dashboard page for your Online Ticket Booking System that displays consolidated data

We will follow these steps:

Create a ViewModel to hold the data for the dashboard.

Create a Dashboard Controller to fetch the data from the repositories.

Create a Razor View to display the dashboard.

Create a Dashboard ViewModel

Create a new class called DashboardViewModel to hold the consolidated data.

Models/DashboardViewModel.cs


public class DashboardViewModel
{
public int TotalUsers { get; set; }
public int TotalRoles { get; set; }
public int TotalEvents { get; set; }
public int TotalTickets { get; set; }
public int TotalBookings { get; set; }
public int TotalPayments { get; set; }
public int TotalNotifications { get; set; }
public int TotalReports { get; set; }
public int TotalSupportTickets { get; set; }
public int TotalFeedbacks { get; set; }
}

Create the Dashboard Controller

Create a new controller called DashboardController to fetch the data from the repositories and pass it to the view.

Controllers/DashboardController.cs


using Microsoft.AspNetCore.Mvc;
public class DashboardController : Controller
{
private readonly UserRepository _userRepository;
private readonly RoleRepository _roleRepository;
private readonly EventRepository _eventRepository;
private readonly TicketRepository _ticketRepository;
private readonly BookingRepository _bookingRepository;
private readonly PaymentRepository _paymentRepository;
private readonly NotificationRepository _notificationRepository;
private readonly ReportRepository _reportRepository;
private readonly SupportTicketRepository _supportTicketRepository;
private readonly FeedbackRepository _feedbackRepository;
public DashboardController(
UserRepository userRepository,
RoleRepository roleRepository,
EventRepository eventRepository,
TicketRepository ticketRepository,
BookingRepository bookingRepository,
PaymentRepository paymentRepository,
NotificationRepository notificationRepository,
ReportRepository reportRepository,
SupportTicketRepository supportTicketRepository,
FeedbackRepository feedbackRepository)
{
_userRepository = userRepository;
_roleRepository = roleRepository;
_eventRepository = eventRepository;
_ticketRepository = ticketRepository;
_bookingRepository = bookingRepository;
_paymentRepository = paymentRepository;
_notificationRepository = notificationRepository;
_reportRepository = reportRepository;
_supportTicketRepository = supportTicketRepository;
_feedbackRepository = feedbackRepository;
}
public IActionResult Index()
{
var model = new DashboardViewModel
{
TotalUsers = _userRepository.GetAllUsers().Count,
TotalRoles = _roleRepository.GetAllRoles().Count,
TotalEvents = _eventRepository.GetAllEvents().Count,
TotalTickets = _ticketRepository.GetAllTickets().Count,
TotalBookings = _bookingRepository.GetAllBookings().Count,
TotalPayments = _paymentRepository.GetAllPayments().Count,
TotalNotifications = _notificationRepository.GetAllNotifications().Count,
TotalReports = _reportRepository.GetAllReports().Count,
TotalSupportTickets = _supportTicketRepository.GetAllSupportTickets().Count,
TotalFeedbacks = _feedbackRepository.GetAllFeedbacks().Count
};
return View(model);
}
}

Create the Dashboard View

Create a Razor view for the dashboard that displays the consolidated data.

Views/Dashboard/Index.cshtml


@model DashboardViewModel
<h2>Dashboard</h2>
<div class="dashboard">
<div class="card">
<h3>Total Users</h3>
<p>@Model.TotalUsers</p>
</div>
<div class="card">
<h3>Total Roles</h3>
<p>@Model.TotalRoles</p>
</div>
<div class="card">
<h3>Total Events</h3>
<p>@Model.TotalEvents</p>
</div>
<div class="card">
<h3>Total Tickets</h3>
<p>@Model.TotalTickets</p>
</div>
<div class="card">
<h3>Total Bookings</h3>
<p>@Model.TotalBookings</p>
</div>
<div class="card">
<h3>Total Payments</h3>
<p>@Model.TotalPayments</p>
</div>
<div class="card">
<h3>Total Notifications</h3>
<p>@Model.TotalNotifications</p>
</div>
<div class="card">
<h3>Total Reports</h3>
<p>@Model.TotalReports</p>
</div>
<div class="card">
<h3>Total Support Tickets</h3>
<p>@Model.TotalSupportTickets</p>
</div>
<div class="card">
<h3>Total Feedbacks</h3>
<p>@Model.TotalFeedbacks</p>
</div>
</div>
<style>
.dashboard {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 20px;
}
.card {
border: 1px solid #ccc;
padding: 20px;
border-radius: 5px;
text-align: center;
}
</style>

Dashboard ViewModel

The DashboardViewModel class holds the data needed for the dashboard.

Dashboard Controller

The DashboardController retrieves the counts from the respective repositories and passes the data to the view.

Dashboard View

The Index.cshtml file displays the total counts of various entities in a card format.

Integration

Make sure to add a route to the DashboardController in your Startup.cs or Program.cs file, depending on your ASP.NET version, to ensure that the dashboard can be accessed from your application.