Project Introduction
The Real Estate Management System is designed to streamline the process of buying, selling, and renting properties. Built using ASP.NET and SQL Server, this application provides a comprehensive platform for users to manage property listings, schedule appointments, process payments, and communicate with potential buyers or renters. The system allows real estate agents and users to efficiently handle property transactions, track appointments, and manage documentation, enhancing the overall experience in the real estate market.
Project Objectives
- To create a secure user authentication system for managing user accounts and roles.
- To enable users to create and manage property listings, including details such as title, description, and price.
- To facilitate the uploading and management of media associated with properties, such as images and videos.
- To allow users to schedule appointments for property viewings.
- To implement a payment processing system for transactions related to property sales or rentals.
- To manage important documents related to properties, such as lease agreements and title deeds.
- To generate reports on property transactions and user activities.
- To provide a messaging system for communication between users and real estate agents.
- To send notifications to users regarding important updates and events.
- To manage marketing campaigns and discounts for properties.
- To collect user feedback to improve the overall system and user experience.
Project Modules
- User Management Module: Handles user registration, login, and role management.
- Property Management Module: Allows users to create, edit, and delete property listings.
- Media Management Module: Facilitates the upload and management of property media.
- Appointment Management Module: Manages scheduling and tracking of property viewings.
- Payment Management Module: Handles payment processing for property transactions.
- Document Management Module: Manages important documents related to properties.
- Report Generation Module: Generates reports on property transactions and user activities.
- Messaging Module: Enables communication between users and real estate agents.
- Notification Module: Sends notifications to users regarding important updates.
- Campaign Management Module: Manages marketing campaigns and discounts for properties.
- Feedback Module: Collects and analyzes user feedback to enhance the system.
SQL Server Database Tables
-- Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(255) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
Phone NVARCHAR(15),
RoleId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- Properties Table
CREATE TABLE Properties (
PropertyId INT PRIMARY KEY IDENTITY(1,1),
Title NVARCHAR(100) NOT NULL,
Description NVARCHAR(MAX),
Address NVARCHAR(255) NOT NULL,
City NVARCHAR(100) NOT NULL,
State NVARCHAR(100) NOT NULL,
ZipCode NVARCHAR(10),
Price DECIMAL(10, 2) NOT NULL,
PropertyType NVARCHAR(50), -- e.g., House, Apartment, Commercial
Status NVARCHAR(20) DEFAULT 'Available', -- e.g., Available, Sold, Pending
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);
-- Media Table
CREATE TABLE Media (
MediaId INT PRIMARY KEY IDENTITY(1,1),
PropertyId INT,
MediaType NVARCHAR(50), -- e.g., Image, Video
MediaUrl NVARCHAR(255) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (PropertyId) REFERENCES Properties(PropertyId)
);
-- Appointments Table
CREATE TABLE Appointments (
AppointmentId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
PropertyId INT,
AppointmentDate DATETIME NOT NULL,
Status NVARCHAR(20) DEFAULT 'Scheduled',
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (PropertyId) REFERENCES Properties(PropertyId)
);
-- Payments Table
CREATE TABLE Payments (
PaymentId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
PropertyId INT,
Amount DECIMAL(10, 2) NOT NULL,
PaymentDate DATETIME DEFAULT GETDATE(),
PaymentMethod NVARCHAR(50), -- e.g., Credit Card, Bank Transfer
Status NVARCHAR(20) DEFAULT 'Pending',
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (PropertyId) REFERENCES Properties(PropertyId)
);
-- Documents Table
CREATE TABLE Documents (
DocumentId INT PRIMARY KEY IDENTITY(1,1),
PropertyId INT,
DocumentType NVARCHAR(50), -- e.g., Lease Agreement, Title Deed
DocumentUrl NVARCHAR(255) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (PropertyId) REFERENCES Properties(PropertyId)
);
-- Reports Table
CREATE TABLE Reports (
ReportId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
PropertyId INT,
ReportDate DATETIME DEFAULT GETDATE(),
Description NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (PropertyId) REFERENCES Properties(PropertyId)
);
-- Messages Table
CREATE TABLE Messages (
MessageId INT PRIMARY KEY IDENTITY(1,1),
SenderId INT,
ReceiverId INT,
MessageText NVARCHAR(MAX),
SentAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (SenderId) REFERENCES Users(UserId),
FOREIGN KEY (ReceiverId) REFERENCES Users(UserId)
);
-- Notifications Table
CREATE TABLE Notifications (
NotificationId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Message NVARCHAR(MAX),
IsRead BIT DEFAULT 0,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Campaigns Table
CREATE TABLE Campaigns (
CampaignId INT PRIMARY KEY IDENTITY(1,1),
CampaignName NVARCHAR(100) NOT NULL,
StartDate DATETIME,
EndDate DATETIME,
DiscountPercentage DECIMAL(5, 2),
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);
-- Feedback Table
CREATE TABLE Feedbacks (
FeedbackId INT PRIMARY KEY IDENTITY(1 ,1),
UserId INT,
Comments NVARCHAR(MAX),
Rating INT CHECK (Rating >= 1 AND Rating <= 5),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
Explanation of Tables
Users: Stores user information, including credentials and roles.
Roles: Defines different roles within the system (e.g., admin, agent, buyer).
Properties: Contains details about properties available for booking.
Media: Manages media files associated with properties, such as images and videos.
Appointments: Tracks appointments for property viewings.
Payments: Records payment transactions related to property bookings.
Documents: Stores important documents related to properties.
Reports: Manages reports submitted by users regarding properties.
Messages: Facilitates communication between users within the system.
Notifications: Keeps track of notifications sent to users.
Campaigns: Manages marketing campaigns for properties.
Feedback: Collects feedback from users regarding their experiences with the platform.
Creating a Model and Repository Pattern
To create a model and repository pattern using ADO.NET for the provided SQL Server tables in an ASP.NET application, we will follow these steps:
Step 1: Create Models
Here are the C# model classes for each table:
public class User
{
public int UserId { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public int? RoleId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
public class Property
{
public int PropertyId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public decimal Price { get; set; }
public string PropertyType { get; set; }
public string Status { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
Step 2: Create Repositories
Next, we will create repository classes for data access. Each repository will contain methods for CRUD operations.
Example Repository for Users:
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 IEnumerable<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(),
Phone = reader["Phone"]?.ToString(),
RoleId = reader["RoleId"] as int?,
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return users;
}
public User GetUser ById(int userId)
{
User user = null;
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())
{
user = new User
{
UserId = (int)reader["User Id"],
Username = reader["Username"].ToString(),
PasswordHash = reader["PasswordHash"].ToString(),
Email = reader["Email"].ToString(),
Phone = reader["Phone"]?.ToString(),
RoleId = reader["RoleId"] as int?,
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return user;
}
public void AddUser (User user)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("INSERT INTO Users (Username, PasswordHash, Email, Phone, RoleId) VALUES (@Username, @PasswordHash, @Email, @Phone, @RoleId)", connection);
command.Parameters.AddWithValue("@Username", user.Username);
command.Parameters.AddWithValue("@PasswordHash", user.PasswordHash);
command.Parameters.AddWithValue("@Email", user.Email);
command.Parameters.AddWithValue("@Phone", (object)user.Phone ?? DBNull.Value);
command.Parameters.AddWithValue("@RoleId", (object)user.RoleId ?? DBNull.Value);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateUser (User user)
{
using (var connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand("UPDATE Users SET Username = @Username, PasswordHash = @PasswordHash, Email = @Email, Phone = @Phone, RoleId = @RoleId, UpdatedAt = GETDATE() 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("@Phone", (object)user.Phone ?? DBNull.Value);
command.Parameters.AddWithValue("@RoleId", (object)user.RoleId ?? DBNull.Value);
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();
}
}
}
Step 3: Implement Other Repositories
You would implement similar repository classes for the other tables (Roles, Properties, Media, Appointments, Payments, Documents, Reports, Messages, Notifications, Campaigns, Feedbacks) following the same pattern as shown above.
Step 4: Usage in ASP.NET
In your ASP.NET application, you can use dependency injection to inject the repository into your controllers or services. Here’s an example of how you might use the User Repository in a controller:
public class UsersController : Controller
{
private readonly UserRepository _userRepository;
public UsersController(UserRepository userRepository)
{
_userRepository = userRepository;
}
public IActionResult Index()
{
var users = _userRepository.GetAllUsers();
return View(users);
}
public IActionResult Details(int id)
{
var user = _userRepository.GetUser ById(id);
if (user == null)
{
return NotFound();
}
return View(user);
}
[HttpPost]
public IActionResult Create(User user)
{
if (ModelState.IsValid)
{
_userRepository.AddUser (user);
return RedirectToAction(nameof(Index));
}
return View(user);
}
[HttpPost]
public IActionResult Edit(User user)
{
if (ModelState.IsValid)
{
_userRepository.UpdateUser (user);
return RedirectToAction(nameof(Index));
}
return View(user);
}
[HttpPost]
public IActionResult Delete(int id)
{
_userRepository.DeleteUser (id);
return RedirectToAction(nameof(Index));
}
}
This structure allows for a clean separation of concerns, where the models represent the data structure, and the repositories handle the data access logic. You can extend this pattern to other entities in your application, ensuring that your code remains organized and maintainable.
Repository Classes
Sure! Below are the repository classes for the remaining models based on the SQL tables you provided. Each repository will include basic CRUD operations similar to the User Repository example.
RoleRepository
public class RoleRepository
{
private readonly string _connectionString;
public RoleRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<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 Role GetRoleById(int roleId) {
Role role = null;
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()) {
role = new Role {
RoleId = (int)reader["RoleId"],
RoleName = reader["RoleName"].ToString()
};
}
}
}
return role;
}
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 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();
}
}
}
PropertyRepository
public class PropertyRepository {
private readonly string _connectionString;
public PropertyRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Property> GetAllProperties() {
var properties = new List<Property>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Properties", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
properties.Add(new Property {
PropertyId = (int)reader["PropertyId"],
Title = reader["Title"].ToString(),
Description = reader["Description"].ToString(),
Address = reader["Address"].ToString(),
City = reader["City"].ToString(),
State = reader["State"].ToString(),
ZipCode = reader["ZipCode"]?.ToString(),
Price = (decimal)reader["Price"],
PropertyType = reader["PropertyType"].ToString(),
Status = reader["Status"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return properties;
}
public Property GetPropertyById(int propertyId) {
Property property = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Properties WHERE PropertyId = @PropertyId", connection);
command.Parameters.AddWithValue("@PropertyId", propertyId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
property = new Property {
PropertyId = (int)reader["PropertyId"],
Title = reader["Title"].ToString(),
Description = reader["Description"].ToString(),
Address = reader["Address"].ToString(),
City = reader["City"].ToString(),
State = reader["State"].ToString(),
ZipCode = reader["ZipCode"]?.ToString(),
Price = (decimal)reader["Price"],
PropertyType = reader["PropertyType"].ToString(),
Status = reader["Status"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return property;
}
public void AddProperty(Property property) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Properties (Title, Description, Address, City, State, ZipCode, Price, PropertyType, Status) VALUES(@Title, @Description, @Address, @City, @State, @ZipCode, @Price, @PropertyType, @Status)", connection);
command.Parameters.AddWithValue("@Title", property.Title);
command.Parameters.AddWithValue("@Description", property.Description);
command.Parameters.AddWithValue("@Address", property.Address);
command.Parameters.AddWithValue("@City", property.City);
command.Parameters.AddWithValue("@State", property.State);
command.Parameters.AddWithValue("@ZipCode", (object)property.ZipCode ?? DBNull.Value);
command.Parameters.AddWithValue("@Price", property.Price);
command.Parameters.AddWithValue("@PropertyType", property.PropertyType);
command.Parameters.AddWithValue("@Status", property.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateProperty(Property property) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Properties SET Title = @Title, Description = @Description, Address = @Address, City = @City, State = @State, ZipCode = @ZipCode, Price = @Price, PropertyType = @PropertyType, Status = @Status, UpdatedAt = GETDATE() WHERE PropertyId = @PropertyId", connection);
command.Parameters.AddWithValue("@PropertyId", property.PropertyId);
command.Parameters.AddWithValue("@Title", property.Title);
command.Parameters.AddWithValue("@Description", property.Description);
command.Parameters.AddWithValue("@Address", property.Address);
command.Parameters.AddWithValue("@City", property.City);
command.Parameters.AddWithValue("@State", property.State);
command.Parameters.AddWithValue("@ZipCode", (object)property.ZipCode ?? DBNull.Value);
command.Parameters.AddWithValue("@Price", property.Price);
command.Parameters.AddWithValue("@PropertyType", property.PropertyType);
command.Parameters.AddWithValue("@Status", property.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteProperty(int propertyId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Properties WHERE PropertyId = @PropertyId", connection);
command.Parameters.AddWithValue("@PropertyId", propertyId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
MediaRepository
public class MediaRepository {
private readonly string _connectionString;
public MediaRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Media> GetAllMedia() {
var mediaList = new List<Media>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Media", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
mediaList.Add(new Media {
MediaId = (int)reader["MediaId"],
PropertyId = (int)reader["PropertyId"],
MediaType = reader["MediaType"].ToString(),
MediaUrl = reader["MediaUrl"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return mediaList;
}
public Media GetMediaById(int mediaId) {
Media media = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Media WHERE MediaId = @MediaId", connection);
command.Parameters.AddWithValue("@MediaId", mediaId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
media = new Media {
MediaId = (int)reader["MediaId"],
PropertyId = (int)reader["PropertyId"],
MediaType = reader["MediaType"].ToString(),
MediaUrl = reader["MediaUrl"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return media;
}
public void AddMedia(Media media) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Media (PropertyId, MediaType, MediaUrl) VALUES (@PropertyId, @MediaType, @MediaUrl)", connection);
command.Parameters.AddWithValue("@PropertyId", media.PropertyId);
command.Parameters.AddWithValue("@MediaType", media.MediaType);
command.Parameters.AddWithValue("@MediaUrl", media.MediaUrl);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateMedia(Media media) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Media SET PropertyId = @PropertyId, MediaType = @MediaType, MediaUrl = @MediaUrl, UpdatedAt = GETDATE() WHERE MediaId = @MediaId", connection);
command.Parameters.AddWithValue("@MediaId", media.MediaId);
command.Parameters.AddWithValue("@PropertyId", media.PropertyId);
command.Parameters.AddWithValue("@MediaType", media.MediaType);
command.Parameters.AddWithValue("@MediaUrl", media.MediaUrl);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteMedia(int mediaId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Media WHERE MediaId = @MediaId", connection);
command.Parameters.AddWithValue("@MediaId", mediaId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
AppointmentRepository
public class AppointmentRepository {
private readonly string _connectionString;
public AppointmentRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Appointment> GetAllAppointments() {
var appointments = new List<Appointment>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Appointments", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
appointments.Add(new Appointment {
AppointmentId = (int)reader["AppointmentId"],
UserId = (int)reader["User Id"],
PropertyId = (int)reader["PropertyId"],
AppointmentDate = (DateTime)reader["AppointmentDate"],
Status = reader["Status"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return appointments;
}
public Appointment GetAppointmentById(int appointmentId) {
Appointment appointment = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Appointments WHERE AppointmentId = @AppointmentId", connection);
command.Parameters.AddWithValue("@AppointmentId", appointmentId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
appointment = new Appointment {
AppointmentId = (int)reader["AppointmentId"],
UserId = (int)reader["User Id"],
PropertyId = (int)reader["PropertyId"],
AppointmentDate = (DateTime)reader["AppointmentDate"],
Status = reader["Status"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return appointment;
}
public void AddAppointment(Appointment appointment) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Appointments (User Id, PropertyId, AppointmentDate, Status) VALUES(@User Id, @PropertyId, @AppointmentDate, @Status)", connection);
command.Parameters.AddWithValue("@User Id", appointment.UserId);
command.Parameters.AddWithValue("@PropertyId", appointment.PropertyId);
command.Parameters.AddWithValue("@AppointmentDate", appointment.AppointmentDate);
command.Parameters.AddWithValue("@Status", appointment.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateAppointment(Appointment appointment) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Appointments SET UserId = @User Id, PropertyId = @PropertyId, AppointmentDate = @AppointmentDate, Status = @Status, UpdatedAt = GETDATE() WHERE AppointmentId = @AppointmentId", connection);
command.Parameters.AddWithValue("@AppointmentId", appointment.AppointmentId);
command.Parameters.AddWithValue("@User Id", appointment.UserId);
command.Parameters.AddWithValue("@PropertyId", appointment.PropertyId);
command.Parameters.AddWithValue("@AppointmentDate", appointment.AppointmentDate);
command.Parameters.AddWithValue("@Status", appointment.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteAppointment(int appointmentId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Appointments WHERE AppointmentId = @AppointmentId", connection);
command.Parameters.AddWithValue("@AppointmentId", appointmentId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
PaymentRepository
public class PaymentRepository {
private readonly string _connectionString;
public PaymentRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<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"],
UserId = (int)reader["User Id"],
PropertyId = (int)reader["PropertyId"],
Amount = (decimal)reader["Amount"],
PaymentDate = (DateTime)reader["PaymentDate"],
PaymentMethod = reader["PaymentMethod"].ToString(),
Status = reader["Status"].ToString()
});
}
}
}
return payments;
}
public Payment GetPaymentById(int paymentId) {
Payment payment = null;
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()) {
payment = new Payment {
PaymentId = (int)reader["PaymentId"],
UserId = (int)reader["User Id"],
PropertyId = (int)reader["PropertyId"],
Amount = (decimal)reader["Amount"],
PaymentDate = (DateTime)reader["PaymentDate"],
PaymentMethod = reader["PaymentMethod"].ToString(),
Status = reader["Status"].ToString()
};
}
}
}
return payment;
}
public void AddPayment(Payment payment) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Payments (User Id, PropertyId, Amount, PaymentDate, PaymentMethod, Status) VALUES(@User Id, @PropertyId, @Amount, @PaymentDate, @PaymentMethod, @Status)", connection);
command.Parameters.AddWithValue("@User Id", payment.UserId);
command.Parameters.AddWithValue("@PropertyId", payment.PropertyId);
command.Parameters.AddWithValue("@Amount", payment.Amount);
command.Parameters.AddWithValue("@PaymentDate", payment.PaymentDate);
command.Parameters.AddWithValue("@PaymentMethod", payment.PaymentMethod);
command.Parameters.AddWithValue("@Status", payment.Status);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdatePayment(Payment payment) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Payments SET UserId = @User Id, PropertyId = @PropertyId, Amount = @Amount, PaymentDate = @PaymentDate, PaymentMethod = @PaymentMethod, Status = @Status WHERE PaymentId = @PaymentId", connection);
command.Parameters.AddWithValue("@PaymentId", payment.PaymentId);
command.Parameters.AddWithValue("@User Id", payment.UserId);
command.Parameters.AddWithValue("@PropertyId", payment.PropertyId);
command.Parameters.AddWithValue("@Amount", payment.Amount);
command.Parameters.AddWithValue("@PaymentDate", payment.PaymentDate);
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();
}
}
}
DocumentRepository
public class DocumentRepository {
private readonly string _connectionString;
public DocumentRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Document> GetAllDocuments() {
var documents = new List<Document>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Documents", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
documents.Add(new Document {
DocumentId = (int)reader["DocumentId"],
PropertyId = (int)reader["PropertyId"],
DocumentType = reader["DocumentType"].ToString(),
DocumentUrl = reader["DocumentUrl"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return documents;
}
public Document GetDocumentById(int documentId) {
Document document = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Documents WHERE DocumentId = @DocumentId", connection);
command.Parameters.AddWithValue("@DocumentId", documentId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
document = new Document {
DocumentId = (int)reader["DocumentId"],
PropertyId = (int)reader["PropertyId"],
DocumentType = reader["DocumentType"].ToString(),
DocumentUrl = reader["DocumentUrl"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return document;
}
public void AddDocument(Document document) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Documents (PropertyId, DocumentType, DocumentUrl) VALUES(@PropertyId, @DocumentType, @DocumentUrl)", connection);
command.Parameters.AddWithValue("@PropertyId", document.PropertyId);
command.Parameters.AddWithValue("@DocumentType", document.DocumentType);
command.Parameters.AddWithValue("@DocumentUrl", document.DocumentUrl);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateDocument(Document document) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Documents SET PropertyId = @PropertyId, DocumentType = @DocumentType, DocumentUrl = @DocumentUrl, UpdatedAt = GETDATE() WHERE DocumentId = @DocumentId", connection);
command.Parameters.AddWithValue("@DocumentId", document.DocumentId);
command.Parameters.AddWithValue("@PropertyId", document.PropertyId);
command.Parameters.AddWithValue("@DocumentType", document.DocumentType);
command.Parameters.AddWithValue("@DocumentUrl", document.DocumentUrl);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteDocument(int documentId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Documents WHERE DocumentId = @DocumentId", connection);
command.Parameters.AddWithValue("@DocumentId", documentId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
ReportRepository
public class ReportRepository {
private readonly string _connectionString;
public ReportRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<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"],
PropertyId = (int)reader["PropertyId"],
ReportDate = (DateTime)reader["ReportDate"],
Description = reader["Description"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return reports;
}
public Report GetReportById(int reportId) {
Report report = null;
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()) {
report = new Report {
ReportId = (int)reader["ReportId"],
UserId = (int)reader["User Id"],
PropertyId = (int)reader["PropertyId"],
ReportDate = (DateTime)reader["ReportDate"],
Description = reader["Description"].ToString(),
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return report;
}
public void AddReport(Report report) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Reports (User Id, PropertyId, ReportDate, Description) VALUES(@User Id, @PropertyId, @ReportDate, @Description)", connection);
command.Parameters.AddWithValue("@User Id", report.UserId);
command.Parameters.AddWithValue("@PropertyId", report.PropertyId);
command.Parameters.AddWithValue("@ReportDate", report.ReportDate);
command.Parameters.AddWithValue("@Description", report.Description);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateReport(Report report) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Reports SET UserId = @User Id, PropertyId = @PropertyId, ReportDate = @ReportDate, Description = @Description, UpdatedAt = GETDATE() WHERE ReportId = @ReportId", connection);
command.Parameters.AddWithValue("@ReportId", report.ReportId);
command.Parameters.AddWithValue("@User Id", report.UserId);
command.Parameters.AddWithValue("@PropertyId", report.PropertyId);
command.Parameters.AddWithValue("@ReportDate", report.ReportDate);
command.Parameters.AddWithValue("@Description", report.Description);
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();
}
}
}
MessageRepository
public class MessageRepository {
private readonly string _connectionString;
public MessageRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Message> GetAllMessages() {
var messages = new List<Message>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Messages", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
messages.Add(new Message {
MessageId = (int)reader["MessageId"],
SenderId = (int)reader["SenderId"],
ReceiverId = (int)reader["ReceiverId"],
MessageText = reader["MessageText"].ToString(),
SentAt = (DateTime)reader["SentAt"]
});
}
}
}
return messages;
}
public Message GetMessageById(int messageId) {
Message message = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Messages WHERE MessageId = @MessageId", connection);
command.Parameters.AddWithValue("@MessageId", messageId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
message = new Message {
MessageId = (int)reader["MessageId"],
SenderId = (int)reader["SenderId"],
ReceiverId = (int)reader["ReceiverId"],
MessageText = reader["MessageText"].ToString(),
SentAt = (DateTime)reader["SentAt"]
};
}
}
}
return message;
}
public void AddMessage(Message message) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Messages (SenderId, ReceiverId, MessageText) VALUES(@SenderId, @ReceiverId, @MessageText)", connection);
command.Parameters.AddWithValue("@SenderId", message.SenderId);
command.Parameters.AddWithValue("@ReceiverId", message.ReceiverId);
command.Parameters.AddWithValue("@MessageText", message.MessageText);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateMessage(Message message) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Messages SET SenderId = @SenderId, ReceiverId = @ReceiverId, MessageText = @MessageText WHERE MessageId = @MessageId", connection);
command.Parameters.AddWithValue("@MessageId", message.MessageId);
command.Parameters.AddWithValue("@SenderId", message.SenderId);
command.Parameters.AddWithValue("@ReceiverId", message.ReceiverId);
command.Parameters.AddWithValue("@MessageText", message.MessageText);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteMessage(int messageId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Messages WHERE MessageId = @MessageId", connection);
command.Parameters.AddWithValue("@MessageId", messageId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
NotificationRepository
public class NotificationRepository {
private readonly string _connectionString;
public NotificationRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<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 Notification GetNotificationById(int notificationId) {
Notification notification = null;
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()) {
notification = new Notification {
NotificationId = (int)reader["NotificationId"],
UserId = (int)reader["User Id"],
Message = reader["Message"].ToString(),
IsRead = (bool)reader["IsRead"],
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return notification;
}
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 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();
}
}
}
CampaignRepository
public class CampaignRepository {
private readonly string _connectionString;
public CampaignRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Campaign> GetAllCampaigns() {
var campaigns = new List<Campaign>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Campaigns", connection);
connection.Open();
using (var reader = command.ExecuteReader()) {
while (reader.Read()) {
campaigns.Add(new Campaign {
CampaignId = (int)reader["CampaignId"],
CampaignName = reader["CampaignName"].ToString(),
StartDate = (DateTime)reader["StartDate"],
EndDate = (DateTime)reader["EndDate"],
DiscountPercentage = (decimal)reader["DiscountPercentage"],
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
});
}
}
}
return campaigns;
}
public Campaign GetCampaignById(int campaignId) {
Campaign campaign = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Campaigns WHERE CampaignId = @CampaignId", connection);
command.Parameters.AddWithValue("@CampaignId", campaignId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
campaign = new Campaign {
CampaignId = (int)reader["CampaignId"],
CampaignName = reader["CampaignName"].ToString(),
StartDate = (DateTime)reader["StartDate"],
EndDate = (DateTime)reader["EndDate"],
DiscountPercentage = (decimal)reader["DiscountPercentage"],
CreatedAt = (DateTime)reader["CreatedAt"],
UpdatedAt = (DateTime)reader["UpdatedAt"]
};
}
}
}
return campaign;
}
public void AddCampaign(Campaign campaign) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Campaigns(CampaignName, StartDate, EndDate, DiscountPercentage) VALUES(@CampaignName, @StartDate, @EndDate, @DiscountPercentage)", connection);
command.Parameters.AddWithValue("@CampaignName", campaign.CampaignName);
command.Parameters.AddWithValue("@StartDate", campaign.StartDate);
command.Parameters.AddWithValue("@EndDate", campaign.EndDate);
command.Parameters.AddWithValue("@DiscountPercentage", campaign.DiscountPercentage);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateCampaign(Campaign campaign) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Campaigns SET CampaignName = @CampaignName, StartDate = @StartDate, EndDate = @EndDate, DiscountPercentage = @DiscountPercentage, UpdatedAt = GETDATE() WHERE CampaignId = @CampaignId", connection);
command.Parameters.AddWithValue("@CampaignId", campaign.CampaignId);
command.Parameters.AddWithValue("@CampaignName", campaign.CampaignName);
command.Parameters.AddWithValue("@StartDate", campaign.StartDate);
command.Parameters.AddWithValue("@EndDate", campaign.EndDate);
command.Parameters.AddWithValue("@DiscountPercentage", campaign.DiscountPercentage);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteCampaign(int campaignId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Campaigns WHERE CampaignId = @CampaignId", connection);
command.Parameters.AddWithValue("@CampaignId", campaignId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
FeedbackRepository
public class FeedbackRepository {
private readonly string _connectionString;
public FeedbackRepository(string connectionString) {
_connectionString = connectionString;
}
public IEnumerable<Feedback> GetAllFeedbacks() {
var feedbacks = new List<Feedback>();
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Feedbacks", 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(),
Rating = (int)reader["Rating"],
CreatedAt = (DateTime)reader["CreatedAt"]
});
}
}
}
return feedbacks;
}
public Feedback GetFeedbackById(int feedbackId) {
Feedback feedback = null;
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("SELECT * FROM Feedbacks WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedbackId);
connection.Open();
using (var reader = command.ExecuteReader()) {
if (reader.Read()) {
feedback = new Feedback {
FeedbackId = (int)reader["FeedbackId"],
UserId = (int)reader["User Id"],
Comments = reader["Comments"].ToString(),
Rating = (int)reader["Rating"],
CreatedAt = (DateTime)reader["CreatedAt"]
};
}
}
}
return feedback;
}
public void AddFeedback(Feedback feedback) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("INSERT INTO Feedbacks(User Id, Comments, Rating) VALUES(@User Id, @Comments, @Rating)", connection);
command.Parameters.AddWithValue("@User Id", feedback.UserId);
command.Parameters.AddWithValue("@Comments", feedback.Comments);
command.Parameters.AddWithValue("@Rating", feedback.Rating);
connection.Open();
command.ExecuteNonQuery();
}
}
public void UpdateFeedback(Feedback feedback) {
using ( var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("UPDATE Feedbacks SET UserId = @User Id, Comments = @Comments, Rating = @Rating WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedback.FeedbackId);
command.Parameters.AddWithValue("@User Id", feedback.UserId);
command.Parameters.AddWithValue("@Comments", feedback.Comments);
command.Parameters.AddWithValue("@Rating", feedback.Rating);
connection.Open();
command.ExecuteNonQuery();
}
}
public void DeleteFeedback(int feedbackId) {
using (var connection = new SqlConnection(_connectionString)) {
var command = new SqlCommand("DELETE FROM Feedbacks WHERE FeedbackId = @FeedbackId", connection);
command.Parameters.AddWithValue("@FeedbackId", feedbackId);
connection.Open();
command.ExecuteNonQuery();
}
}
}
With these repository classes, you now have a complete set of data access layers for all the models based on the SQL tables you provided. Each repository follows the same pattern, allowing for easy maintenance and scalability in your ASP.NET application. You can now integrate these repositories into your controllers or services as needed.
ASP.NET MVC Controllers
Certainly! Below are example ASP.NET MVC controllers for each of the repositories we created earlier. Each controller will handle basic CRUD operations and will be set up to work with views.
UserController
public class UsersController : Controller
{
private readonly UserRepository _userRepository;
public UsersController(UserRepository userRepository)
{
_userRepository = userRepository;
}
public IActionResult Index()
{
var users = _userRepository.GetAllUsers();
return View(users);
}
public IActionResult Details(int id)
{
var user = _userRepository.GetUser ById(id);
if (user == null)
{
return NotFound();
}
return View(user);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(User user)
{
if (ModelState.IsValid)
{
_userRepository.AddUser (user);
return RedirectToAction(nameof(Index));
}
return View(user);
}
public IActionResult Edit(int id)
{
var user = _userRepository.GetUser ById(id);
if (user == null)
{
return NotFound();
}
return View(user);
}
[HttpPost]
public IActionResult Edit(User user)
{
if (ModelState.IsValid)
{
_userRepository.UpdateUser (user);
return RedirectToAction(nameof(Index));
}
return View(user);
}
public IActionResult Delete(int id)
{
var user = _userRepository.GetUser ById(id);
if (user == null)
{
return NotFound();
}
return View(user);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_userRepository.DeleteUser (id);
return RedirectToAction(nameof(Index));
}
}
RoleController
public class RolesController : Controller
{
private readonly RoleRepository _roleRepository;
public RolesController(RoleRepository roleRepository)
{
_roleRepository = roleRepository;
}
public IActionResult Index()
{
var roles = _roleRepository.GetAllRoles();
return View(roles);
}
public IActionResult Details(int id)
{
var role = _roleRepository.GetRoleById(id);
if (role == null)
{
return NotFound();
}
return View(role);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Role role)
{
if (ModelState.IsValid)
{
_roleRepository.AddRole(role);
return RedirectToAction(nameof(Index));
}
return View(role);
}
public IActionResult Edit(int id)
{
var role = _roleRepository.GetRoleById(id);
if (role == null)
{
return NotFound();
}
return View(role);
}
[HttpPost]
public IActionResult Edit(Role role)
{
if (ModelState.IsValid)
{
_roleRepository.UpdateRole(role);
return RedirectToAction(nameof(Index));
}
return View(role);
}
public IActionResult Delete(int id)
{
var role = _roleRepository.GetRoleById(id);
if (role == null)
{
return NotFound();
}
return View(role);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_roleRepository.DeleteRole(id);
return RedirectToAction(nameof(Index));
}
}
PropertyController
public class PropertiesController : Controller
{
private readonly PropertyRepository _propertyRepository;
public PropertiesController(PropertyRepository propertyRepository)
{
_propertyRepository = propertyRepository;
}
public IActionResult Index()
{
var properties = _propertyRepository.GetAllProperties();
return View(properties);
}
public IActionResult Details(int id)
{
var property = _propertyRepository.GetPropertyById(id);
if (property == null)
{
return NotFound();
}
return View(property);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Property property)
{
if (ModelState.IsValid)
{
_propertyRepository.AddProperty(property);
return RedirectToAction(nameof(Index));
}
return View(property);
}
public IActionResult Edit(int id)
{
var property = _propertyRepository.GetPropertyById(id);
if (property == null)
{
return NotFound();
}
return View(property);
}
[HttpPost]
public IActionResult Edit(Property property)
{
if (ModelState.IsValid)
{
_propertyRepository.UpdateProperty(property);
return RedirectToAction(nameof(Index));
}
return View(property);
}
public IActionResult Delete(int id)
{
var property = _propertyRepository.GetPropertyById(id);
if (property == null)
{
return NotFound();
}
return View(property);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_propertyRepository.DeleteProperty(id);
return RedirectToAction(nameof(Index));
}
}
MediaController
public class MediaController : Controller
{
private readonly MediaRepository _mediaRepository;
public MediaController(MediaRepository mediaRepository)
{
_mediaRepository = mediaRepository;
}
public IActionResult Index()
{
var mediaList = _mediaRepository.GetAllMedia();
return View(mediaList);
}
public IActionResult Details(int id)
{
var media = _mediaRepository.GetMediaById(id);
if (media == null)
{
return NotFound();
}
return View(media);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Media media)
{
if (ModelState.IsValid)
{
_mediaRepository.AddMedia(media);
return RedirectToAction(nameof(Index));
}
return View(media);
}
public IActionResult Edit(int id)
{
var media = _mediaRepository.GetMediaById(id);
if (media == null)
{
return NotFound();
}
return View(media);
}
[HttpPost]
public IActionResult Edit(Media media)
{
if (ModelState.IsValid)
{
_mediaRepository.UpdateMedia(media);
return RedirectToAction(nameof(Index));
}
return View(media);
}
public IActionResult Delete(int id)
{
var media = _mediaRepository.GetMediaById(id);
if (media == null)
{
return NotFound();
}
return View(media);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_mediaRepository.DeleteMedia(id);
return RedirectToAction(nameof(Index));
}
}
AppointmentController
public class AppointmentsController : Controller
{
private readonly AppointmentRepository _appointmentRepository;
public AppointmentsController(AppointmentRepository appointmentRepository)
{
_appointmentRepository = appointmentRepository;
}
public IActionResult Index()
{
var appointments = _appointmentRepository.GetAllAppointments();
return View(appointments);
}
public IActionResult Details(int id)
{
var appointment = _appointmentRepository.GetAppointmentById(id);
if (appointment == null)
{
return NotFound();
}
return View(appointment);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Appointment appointment)
{
if (ModelState.IsValid)
{
_appointmentRepository.AddAppointment(appointment);
return RedirectToAction(nameof(Index));
}
return View(appointment);
}
public IActionResult Edit(int id)
{
var appointment = _appointmentRepository.GetAppointmentById(id);
if (appointment == null)
{
return NotFound();
}
return View(appointment);
}
[HttpPost]
public IActionResult Edit(Appointment appointment)
{
if (ModelState.IsValid)
{
_appointmentRepository.UpdateAppointment(appointment);
return RedirectToAction(nameof(Index));
}
return View(appointment);
}
public IActionResult Delete(int id)
{
var appointment = _appointmentRepository.GetAppointmentById(id);
if (appointment == null)
{
return NotFound();
}
return View(appointment);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_appointmentRepository.DeleteAppointment(id);
return RedirectToAction(nameof(Index));
}
}
PaymentController
public class PaymentsController : Controller
{
private readonly PaymentRepository _paymentRepository;
public PaymentsController(PaymentRepository paymentRepository)
{
_paymentRepository = paymentRepository;
}
public IActionResult Index()
{
var payments = _paymentRepository.GetAllPayments();
return View(payments);
}
public IActionResult Details(int id)
{
var payment = _paymentRepository.GetPaymentById(id);
if (payment == null)
{
return NotFound();
}
return View(payment);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Payment payment)
{
if (ModelState.IsValid)
{
_paymentRepository.AddPayment(payment);
return RedirectToAction(nameof(Index));
}
return View(payment);
}
public IActionResult Edit(int id)
{
var payment = _paymentRepository.GetPaymentById(id);
if (payment == null)
{
return NotFound();
}
return View(payment);
}
[HttpPost]
public IActionResult Edit(Payment payment)
{
if (ModelState.IsValid)
{
_paymentRepository.UpdatePayment(payment);
return RedirectToAction(nameof(Index));
}
return View(payment);
}
public IActionResult Delete(int id)
{
var payment = _paymentRepository.GetPaymentById(id);
if (payment == null)
{
return NotFound();
}
return View(payment);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_paymentRepository.DeletePayment(id);
return RedirectToAction(nameof(Index));
}
}
DocumentController
public class DocumentsController : Controller
{
private readonly DocumentRepository _documentRepository;
public DocumentsController(DocumentRepository documentRepository)
{
_documentRepository = documentRepository;
}
public IActionResult Index()
{
var documents = _documentRepository.GetAllDocuments();
return View(documents);
}
public IActionResult Details(int id)
{
var document = _documentRepository.GetDocumentById(id);
if (document == null)
{
return NotFound();
}
return View(document);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Document document)
{
if (ModelState.IsValid)
{
_documentRepository.AddDocument(document);
return RedirectToAction(nameof(Index));
}
return View(document);
}
public IActionResult Edit(int id)
{
var document = _documentRepository.GetDocumentById(id);
if (document == null)
{
return NotFound();
}
return View(document);
}
[HttpPost]
public IActionResult Edit(Document document)
{
if (ModelState.IsValid)
{
_documentRepository.UpdateDocument(document);
return RedirectToAction(nameof(Index));
}
return View(document);
}
public IActionResult Delete(int id)
{
var document = _documentRepository.GetDocumentById(id);
if (document == null)
{
return NotFound();
}
return View(document);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_documentRepository.DeleteDocument(id);
return RedirectToAction(nameof(Index));
}
}
ReportController
public class ReportsController : Controller
{
private readonly ReportRepository _reportRepository;
public ReportsController(ReportRepository reportRepository)
{
_reportRepository = reportRepository;
}
public IActionResult Index()
{
var reports = _reportRepository.GetAllReports();
return View(reports);
}
public IActionResult Details(int id)
{
var report = _reportRepository.GetReportById(id);
if (report == null)
{
return NotFound();
}
return View(report);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Report report)
{
if (ModelState.IsValid)
{
_reportRepository.AddReport(report);
return RedirectToAction(nameof(Index));
}
return View(report);
}
public IActionResult Edit(int id)
{
var report = _reportRepository.GetReportById(id);
if (report == null)
{
return NotFound();
}
return View(report);
}
[HttpPost]
public IActionResult Edit(Report report)
{
if (ModelState.IsValid)
{
_reportRepository.UpdateReport(report);
return RedirectToAction(nameof(Index));
}
return View(report);
}
public IActionResult Delete(int id)
{
var report = _reportRepository.GetReportById(id);
if (report == null)
{
return NotFound();
}
return View(report);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_reportRepository.DeleteReport(id);
return RedirectToAction(nameof(Index));
}
}
MessageController
public class MessagesController : Controller
{
private readonly MessageRepository _messageRepository;
public MessagesController(MessageRepository messageRepository)
{
_messageRepository = messageRepository;
}
public IActionResult Index()
{
var messages = _messageRepository.GetAllMessages();
return View(messages);
}
public IActionResult Details(int id)
{
var message = _messageRepository.GetMessageById(id);
if (message == null)
{
return NotFound();
}
return View(message);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Message message)
{
if (ModelState.IsValid)
{
_messageRepository.AddMessage(message);
return RedirectToAction(nameof(Index));
}
return View(message);
}
public IActionResult Edit(int id)
{
var message = _messageRepository.GetMessageById(id);
if (message == null)
{
return NotFound();
}
return View(message);
}
[HttpPost]
public IActionResult Edit(Message message)
{
if (ModelState.IsValid)
{
_messageRepository.UpdateMessage(message);
return RedirectToAction(nameof(Index));
}
return View(message);
}
public IActionResult Delete(int id)
{
var message = _messageRepository.GetMessageById(id);
if (message == null)
{
return NotFound();
}
return View(message);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_messageRepository.DeleteMessage(id);
return RedirectToAction(nameof(Index));
}
}
NotificationController
public class NotificationsController : Controller
{
private readonly NotificationRepository _notificationRepository;
public NotificationsController(NotificationRepository notificationRepository)
{
_notificationRepository = notificationRepository;
}
public IActionResult Index()
{
var notifications = _notificationRepository.GetAllNotifications();
return View(notifications);
}
public IActionResult Details(int id)
{
var notification = _notificationRepository.GetNotificationById(id);
if (notification == null)
{
return Not Found();
}
return View(notification);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Notification notification)
{
if (ModelState.IsValid)
{
_notificationRepository.AddNotification(notification);
return RedirectToAction(nameof(Index));
}
return View(notification);
}
public IActionResult Edit(int id)
{
var notification = _notificationRepository.GetNotificationById(id);
if (notification == null)
{
return NotFound();
}
return View(notification);
}
[HttpPost]
public IActionResult Edit(Notification notification)
{
if (ModelState.IsValid)
{
_notificationRepository.UpdateNotification(notification);
return RedirectToAction(nameof(Index));
}
return View(notification);
}
public IActionResult Delete(int id)
{
var notification = _notificationRepository.GetNotificationById(id);
if (notification == null)
{
return NotFound();
}
return View(notification);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_notificationRepository.DeleteNotification(id);
return RedirectToAction(nameof(Index));
}
}
CampaignController
public class CampaignsController : Controller
{
private readonly CampaignRepository _campaignRepository;
public CampaignsController(CampaignRepository campaignRepository)
{
_campaignRepository = campaignRepository;
}
public IActionResult Index()
{
var campaigns = _campaignRepository.GetAllCampaigns();
return View(campaigns);
}
public IActionResult Details(int id)
{
var campaign = _campaignRepository.GetCampaignById(id);
if (campaign == null)
{
return NotFound();
}
return View(campaign);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Campaign campaign)
{
if (ModelState.IsValid)
{
_campaignRepository.AddCampaign(campaign);
return RedirectToAction(nameof(Index));
}
return View(campaign);
}
public IActionResult Edit(int id)
{
var campaign = _campaignRepository.GetCampaignById(id);
if (campaign == null)
{
return NotFound();
}
return View(campaign);
}
[HttpPost]
public IActionResult Edit(Campaign campaign)
{
if (ModelState.IsValid)
{
_campaignRepository.UpdateCampaign(campaign);
return RedirectToAction(nameof(Index));
}
return View(campaign);
}
public IActionResult Delete(int id)
{
var campaign = _campaignRepository.GetCampaignById(id);
if (campaign == null)
{
return NotFound();
}
return View(campaign);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_campaignRepository.DeleteCampaign(id);
return RedirectToAction(nameof(Index));
}
}
FeedbackController
public class FeedbacksController : Controller
{
private readonly FeedbackRepository _feedbackRepository;
public FeedbacksController(FeedbackRepository feedbackRepository)
{
_feedbackRepository = feedbackRepository;
}
public IActionResult Index()
{
var feedbacks = _feedbackRepository.GetAllFeedbacks();
return View(feedbacks);
}
public IActionResult Details(int id)
{
var feedback = _feedbackRepository.GetFeedbackById(id);
if (feedback == null)
{
return NotFound();
}
return View(feedback);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Feedback feedback)
{
if (ModelState.IsValid)
{
_feedbackRepository.AddFeedback(feedback);
return RedirectToAction(nameof(Index));
}
return View(feedback);
}
public IActionResult Edit(int id)
{
var feedback = _feedbackRepository.GetFeedbackById(id);
if (feedback == null)
{
return NotFound();
}
return View(feedback);
}
[HttpPost]
public IActionResult Edit(Feedback feedback)
{
if (ModelState.IsValid)
{
_feedbackRepository.UpdateFeedback(feedback);
return RedirectToAction(nameof(Index));
}
return View(feedback);
}
public IActionResult Delete(int id)
{
var feedback = _feedbackRepository.GetFeedbackById(id);
if (feedback == null)
{
return NotFound();
}
return View(feedback);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
_feedbackRepository.DeleteFeedback(id);
return RedirectToAction(nameof(Index));
}
}
Conclusion
With these controllers, you now have a complete set of ASP.NET MVC controllers for each repository, allowing you to perform CRUD operations on your models. Each controller is structured to handle requests, interact with the corresponding repository, and return views for displaying data. You can now create views for each action method to provide a user interface for managing your data effectively.
Creating Views
Creating views for each of the controllers involves creating Razor view files that correspond to the actions in the controllers. Below, I will provide a basic structure for the views for each controller, including the Index, Details, Create, Edit, and Delete views.
Folder Structure
Assuming you have a standard ASP.NET MVC project structure, the views for each controller will be placed in their respective folders under the Views directory. For example, views for the UsersController will be in Views/Users.
User Views
Views/Users/Index.cshtml
@model IEnumerable<YourNamespace.Models.User
<h2>Users</h2>
<a asp-action="Create" class="btn btn-primary">Create New User</a>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Phone</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var user in Model)
{
<tr>
<td>@user.Username</td>
<td>@user.Email</td>
<td>@user.Phone</td>
<td>
<a asp-action="Details" asp-route-id="@user.UserId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@user.UserId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@user.UserId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Views/Users/Details.cshtml
@model YourNamespace.Models.User
<h2>User Details</h2>
<div>
<h4>@Model.Username</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Email</dt>
<dd class="col-sm-10">@Model.Email</dd>
<dt class="col-sm-2">Phone</dt>
<dd class="col-sm-10">@Model.Phone</dd>
<dt class="col-sm-2">Created At</dt>
<dd class="col-sm-10">@Model.CreatedAt</dd>
<dt class="col-sm-2">Updated At</dt>
<dd class="col-sm-10">@Model.UpdatedAt</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.UserId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Users/Create.cshtml
@model YourNamespace.Models.User
<h2>Create User</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Username"></label>
<input asp-for="Username" class="form-control" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PasswordHash"></label>
<input asp-for="PasswordHash" class="form-control" />
<span asp-validation-for="PasswordHash" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Phone"></label>
<input asp-for="Phone" class="form-control" />
<span asp-validation-for="Phone" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Users/Edit.cshtml
@model YourNamespace.Models.User
<h2>Edit User</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="User Id" />
<div class="form-group">
<label asp-for="Username"></label>
<input asp-for="Username" class="form-control" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PasswordHash"></label>
<input asp-for="PasswordHash" class="form-control" />
<span asp-validation-for="PasswordHash" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Phone"></label>
<input asp-for="Phone" class="form-control" />
<span asp-validation-for="Phone" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Users/Delete.cshtml
@model YourNamespace.Models.User
<h2>Delete User</h2>
<div>
<h4>Are you sure you want to delete this user?</h4>
<div>
<h4>@Model.Username</h4>
<dl class="row">
<dt class="col-sm-2">Email</dt>
<dd class="col-sm-10">@Model.Email</dd>
<dt class="col-sm-2">Phone</dt>
<dd class="col-sm-10">@Model.Phone</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="User Id" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Role Views
Views/Roles/Index.cshtml
@model IEnumerable<YourNamespace.Models.Role>
<h2>Roles</h2>
<a asp-action="Create" class="btn btn-primary">Create New Role</a>
<table class=" table">
<thead>
<tr>
<th>Role Name</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var role in Model)
{
<tr>
<td>@role.Name</td>
<td>@role.Description</td>
<td>
<a asp-action="Details" asp-route-id="@role.RoleId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@role.RoleId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@role.RoleId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Views/Roles/Details.cshtml
@model YourNamespace.Models.Role
<h2>Role Details</h2>
<div>
<h4>@Model.Name</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.RoleId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Roles/Create.cshtml
@model YourNamespace.Models.Role
<h2>Create Role</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Roles/Edit.cshtml
@model YourNamespace.Models.Role
<h2>Edit Role</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="RoleId" />
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Roles/Delete.cshtml
@model YourNamespace.Models.Role
<h2>Delete Role</h2>
<div>
<h4>Are you sure you want to delete this role?</h4>
<div>
<h4>@Model.Name</h4>
<dl class="row">
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="RoleId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Property Views
Views/Properties/Index.cshtml
@model IEnumerable<YourNamespace.Models.Property>
<h2>Properties</h2>
<a asp-action="Create" class="btn btn-primary">Create New Property</a>
<table class="table">
<thead>
<tr>
<th>Property Name</th>
<th>Location</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var property in Model)
{
<tr>
<td>@property.Name</td>
<td>@property.Location</td>
<td>@property.Price</td>
<td>
<a asp-action="Details" asp-route-id="@property.PropertyId " class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@property.PropertyId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@property.PropertyId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Views/Properties/Details.cshtml
@model YourNamespace.Models.Property
<h2>Property Details</h2>
<div>
<h4>@Model.Name</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Location</dt>
<dd class="col-sm-10">@Model.Location</dd>
<dt class="col-sm-2">Price</dt>
<dd class="col-sm-10">@Model.Price</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.PropertyId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Properties/Create.cshtml
@model YourNamespace.Models.Property
<h2>Create Property</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Location"></label>
<input asp-for="Location" class="form-control" />
<span asp-validation-for="Location" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Price"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Properties/Edit.cshtml
@model YourNamespace.Models.Property
<h2>Edit Property</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="PropertyId" />
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Location"></label>
<input asp-for="Location" class="form-control" />
<span asp-validation-for="Location" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Price"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Properties/Delete.cshtml
@model YourNamespace.Models.Property
<h2>Delete Property</h2>
<div>
<h4>Are you sure you want to delete this property?</h4>
<div>
<h4>@Model.Name</h4>
<dl class="row">
<dt class="col-sm-2">Location</dt>
<dd class="col-sm-10">@Model.Location</dd>
<dt class="col-sm-2">Price</dt>
<dd class="col-sm-10">@Model.Price</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="PropertyId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Media Views
Views/Media/Index.cshtml
@model IEnumerable<YourNamespace.Models.Media>
<h2>Media</h2>
<a asp-action="Create" class="btn btn-primary">Upload New Media</a>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var media in Model)
{
<tr>
<td>@media.Title</td>
<td>@media.Type</td>
<td>
<a asp-action="Details" asp-route-id="@media.MediaId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@media.MediaId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@media.MediaId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Views/Media/Details.cshtml
@model YourNamespace.Models.Media
<h2>Media Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Type</dt>
<dd class="col-sm-10">@Model.Type</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.MediaId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Media/Create.cshtml
@model YourNamespace.Models.Media
<h2>Upload Media</h2>
<form asp-action="Create" enctype="multipart/form-data">
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Type"></label>
<input asp-for="Type" class="form-control" />
<span asp-validation-for="Type" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File"></label>
<input asp-for="File" type="file" class="form-control" />
<span asp-validation-for="File" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Upload</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Media/Edit.cshtml
@model YourNamespace.Models.Media
<h2>Edit Media</h2>
<form asp-action="Edit" enctype="multipart/form-data">
<input type="hidden" asp-for="MediaId" />
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Type"></label>
<input asp-for="Type" class="form-control" />
<span asp-validation-for="Type" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File"></label>
<input asp-for="File" type="file" class="form-control" />
<span asp-validation-for="File" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Media/Delete.cshtml
@model YourNamespace.Models.Media
<h2>Delete Media</h2>
<div>
<h4>Are you sure you want to delete this media?</h4>
<div>
<h4>@Model.Title</h4>
<dl class="row">
<dt class="col-sm-2">Type</dt>
<dd class="col-sm-10">@Model.Type</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="MediaId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Appointment Views
Views/Appointments/Index.cshtml
@model IEnumerable<YourNamespace.Models.Appointment>
<h2>Appointments</h2>
<a asp-action="Create" class="btn btn-primary">Schedule New Appointment</a>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var appointment in Model)
{
<tr>
<td>@appointment.Title</td>
<td>@appointment.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@appointment.AppointmentId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@appointment.AppointmentId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@appointment.AppointmentId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Views/Appointments/Details.cshtml
@model YourNamespace.Models.Appointment
<h2>Appointment Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.AppointmentId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Appointments/Create.cshtml
@model YourNamespace.Models.Appointment
<h2>Schedule Appointment</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Date"></label>
<input asp-for="Date" class="form-control" type="datetime-local" />
<span asp-validation-for="Date" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Schedule</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Appointments/Edit.cshtml
@model YourNamespace.Models.Appointment
<h2>Edit Appointment</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="AppointmentId" />
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Date"></label>
<input asp-for="Date" class="form-control" type="datetime-local" />
<span asp-validation-for="Date" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Appointments/Delete.cshtml
@model YourNamespace.Models.Appointment
<h2>Delete Appointment</h2>
<div>
<h4>Are you sure you want to delete this appointment?</h4>
<div>
<h4>@Model.Title</h4>
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="AppointmentId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Payment Views
Views/Payments/Index.cshtml
@model IEnumerable<YourNamespace.Models.Payment>
<h2>Payments</h2>
<a asp-action="Create" class="btn btn-primary">Add New Payment</a>
<table class="table">
<thead>
<tr>
<th>Amount</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var payment in Model)
{
<tr>
<td>@payment.Amount</td>
<td>@payment.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@payment.PaymentId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@payment.PaymentId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@payment.PaymentId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Payment Views
Views/Payments/Index.cshtml
@model YourNamespace.Models.Payment
<h2>Payment Details</h2>
<div>
<h4>Payment of @Model.Amount</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.PaymentId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Payments/Details.cshtml
@model YourNamespace.Models.Payment
<h2>Add Payment</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Amount"></label>
<input asp-for="Amount" class="form-control" />
<span asp-validation-for="Amount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Date"></label>
<input asp-for="Date" class="form-control" type="datetime-local" />
<span asp-validation-for="Date" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Add</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Payments/Create.cshtml
@model YourNamespace.Models.Payment
<h2>Edit Payment</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="PaymentId" />
<div class="form-group">
<label asp-for="Amount"></label>
<input asp-for="Amount" class="form-control" />
<span asp-validation-for="Amount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Date"></label>
<input asp-for="Date" class="form-control" type="datetime-local" />
<span asp-validation-for="Date" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class=" btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Payments/Edit.cshtml
@model YourNamespace.Models.Payment
<h2>Delete Payment</h2>
<div>
<h4>Are you sure you want to delete this payment?</h4>
<div>
<h4>Payment of @Model.Amount</h4>
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="PaymentId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Payments/Delete.cshtml
@model IEnumerable<YourNamespace.Models.Document>
<h2>Documents</h2>
<a asp-action="Create" class="btn btn-primary">Upload New Document</a>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Upload Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var document in Model)
{
<tr>
<td>@document.Title</td>
<td>@document.UploadDate.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@document.DocumentId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@document.DocumentId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@document.DocumentId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Document Views
Views/Documents/Index.cshtml
@model YourNamespace.Models.Document
<h2>Document Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Upload Date</dt>
<dd class="col-sm-10">@Model.UploadDate.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.DocumentId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Documents/Details.cshtml
@model YourNamespace.Models.Document
<h2>Upload Document</h2>
<form asp-action="Create" enctype="multipart/form-data">
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File"></label>
<input asp-for="File" type="file" class="form-control" />
<span asp-validation-for="File" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Upload</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Documents/Create.cshtml
@model YourNamespace.Models.Document
<h2>Edit Document</h2>
<form asp-action="Edit" enctype="multipart/form-data">
<input type="hidden" asp-for="DocumentId" />
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File"></label>
<input asp-for="File" type="file" class="form-control" />
<span asp-validation-for="File" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Documents/Edit.cshtml
@model YourNamespace.Models.Document
<h2>Delete Document</h2>
<div>
<h4>Are you sure you want to delete this document?</h4>
<div>
<h4>@Model.Title</h4>
<dl class="row">
<dt class="col-sm-2">Upload Date</dt>
<dd class="col-sm-10">@Model.UploadDate.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="DocumentId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Documents/Delete.cshtml
@model IEnumerable<YourNamespace.Models.Report>
<h2>Reports</h2>
<a asp-action="Create" class="btn btn-primary">Generate New Report</a>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var report in Model)
{
<tr>
<td>@report.Title</td>
<td>@report.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@report.ReportId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@report.ReportId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@report.ReportId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Report Views
Views/Reports/Index.cshtml
@model YourNamespace.Models.Report
<h2>Report Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.ReportId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Reports/Details.cshtml
@model YourNamespace.Models.Report
<h2>Generate Report</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Generate</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Reports/Create.cshtml
@model YourNamespace.Models.Report
<h2>Edit Report</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="ReportId" />
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp -for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Reports/Edit.cshtml
@model YourNamespace.Models.Report
<h2>Delete Report</h2>
<div>
<h4>Are you sure you want to delete this report?</h4>
<div>
<h4>@Model.Title</h4>
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="ReportId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Reports/Delete.cshtml
@model IEnumerable<YourNamespace.Models.Message>
<h2>Messages</h2>
<a asp-action="Create" class="btn btn-primary">Send New Message</a>
<table class="table">
<thead>
<tr>
<th>Subject</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var message in Model)
{
<tr>
<td>@message.Subject</td>
<td>@message.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@message.MessageId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@message.MessageId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@message.MessageId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Message Views
Views/Messages/Index.cshtml
@model YourNamespace.Models.Message
<h2>Message Details</h2>
<div>
<h4>@Model.Subject</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.MessageId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Messages/Details.cshtml
@model YourNamespace.Models.Message
<h2>Send Message</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Subject"></label>
<input asp-for="Subject" class="form-control" />
<span asp-validation-for="Subject" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Send</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Messages/Create.cshtml
@model YourNamespace.Models.Message
<h2>Edit Message</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="MessageId" />
<div class="form-group">
<label asp-for="Subject"></label>
<input asp-for="Subject" class="form-control" />
<span asp-validation-for="Subject" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Messages/Edit.cshtml
@model YourNamespace.Models.Message
<h2>Delete Message</h2>
<div>
<h4>Are you sure you want to delete this message?</h4>
<div>
<h4>@Model.Subject</h4>
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="MessageId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Messages/Delete.cshtml
@model IEnumerable<YourNamespace.Models.Notification>
<h2>Notifications</h2>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var notification in Model)
{
<tr>
<td>@notification.Title</td>
<td>@notification.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@notification.NotificationId" class="btn btn-info">Details</a>
</td>
</tr>
}
</tbody>
</table>
Notification Views
Views/Notifications/Index.cshtml
@model YourNamespace.Models.Notification
<h2>Notification Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Notifications/Details.cshtml
@model IEnumerable<YourNamespace.Models.Campaign>
<h2>Campaigns</h2>
<a asp-action="Create" class="btn btn-primary">Create New Campaign</a>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Start Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var campaign in Model)
{
<tr>
<td>@campaign.Title</td>
<td>@campaign.StartDate.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@campaign.CampaignId" class="btn btn-info">Details</a>
<a asp-action="Edit" asp-route-id="@campaign.CampaignId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@campaign.CampaignId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Campaign Views
Views/Campaigns/Index.cshtml
@model YourNamespace.Models.Campaign
<h2>Campaign Details</h2>
<div>
<h4>@Model.Title</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Start Date</dt>
<dd class="col-sm-10">@Model.StartDate.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.CampaignId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Campaigns/Details.cshtml
@model YourNamespace.Models.Campaign
<h2>Create Campaign</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StartDate"></label>
<input asp-for="StartDate" class="form-control" type="datetime-local" />
<span asp-validation-for="StartDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Campaigns/Create.cshtml
@model YourNamespace.Models.Campaign
<h2>Edit Campaign</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="CampaignId" />
<div class="form-group">
<label asp-for="Title"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StartDate"></label>
<input asp-for="StartDate" class="form-control" type="datetime-local" />
<span asp-validation-for="StartDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Campaigns/Edit.cshtml
@model YourNamespace.Models.Campaign
<h2>Delete Campaign</h2>
<div>
<h4>Are you sure you want to delete this campaign?</h4>
<div>
<h4>@Model.Title</h4>
<dl class="row">
<dt class="col-sm-2">Start Date</dt>
<dd class="col-sm-10">@Model.StartDate.ToString("g")</dd>
<dt class="col-sm-2">Description</dt>
<dd class="col-sm-10">@Model.Description</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="CampaignId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Campaigns/Delete.cshtml
@model IEnumerable<YourNamespace.Models.Feedback>
<h2>Feedbacks</h2>
<a asp-action="Create" class="btn btn-primary">Submit New Feedback</a>
<table class="table">
<thead>
<tr>
<th>Subject</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var feedback in Model)
{
<tr>
<td>@feedback.Subject</td>
<td>@feedback.Date.ToString("g")</td>
<td>
<a asp-action="Details" asp-route-id="@feedback.FeedbackId" class="btn btn-info">Details </a>
<a asp-action="Edit" asp-route-id="@feedback.FeedbackId" class="btn btn-warning">Edit</a>
<a asp-action="Delete" asp-route-id="@feedback.FeedbackId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Feedback Views
Views/Feedbacks/Index.cshtml
@model YourNamespace.Models.Feedback
<h2>Feedback Details</h2>
<div>
<h4>@Model.Subject</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
<a asp-action="Edit" asp-route-id="@Model.FeedbackId" class="btn btn-warning">Edit</a>
<a asp-action="Index" class="btn btn-primary">Back to List</a>
</div>
Views/Feedbacks/Details.cshtml
@model YourNamespace.Models.Feedback
<h2>Submit Feedback</h2>
<form asp-action="Create">
<div class="form-group">
<label asp-for="Subject"></label>
<input asp-for="Subject" class="form-control" />
<span asp-validation-for="Subject" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Feedbacks/Create.cshtml
@model YourNamespace.Models.Feedback
<h2>Edit Feedback</h2>
<form asp-action="Edit">
<input type="hidden" asp-for="FeedbackId" />
<div class="form-group">
<label asp-for="Subject"></label>
<input asp-for="Subject" class="form-control" />
<span asp-validation-for="Subject" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Content"></label>
<textarea asp-for="Content" class="form-control"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
Views/Feedbacks/Edit.cshtml
@model YourNamespace.Models.Feedback
<h2>Delete Feedback</h2>
<div>
<h4>Are you sure you want to delete this feedback?</h4>
<div>
<h4>@Model.Subject</h4>
<dl class="row">
<dt class="col-sm-2">Date</dt>
<dd class="col-sm-10">@Model.Date.ToString("g")</dd>
<dt class="col-sm-2">Content</dt>
<dd class="col-sm-10">@Model.Content</dd>
</dl>
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="FeedbackId" />
<button type="submit" class="btn btn-danger">Delete</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
</div>
Views/Feedbacks/Delete.cshtml
public class DashboardViewModel
{
public int TotalUsers { get; set; }
public int TotalRoles { get; set; }
public int TotalProperties { get; set; }
public int TotalAppointments { get; set; }
public int TotalPayments { get; set; }
public int TotalDocuments { get; set; }
public int TotalReports { get; set; }
public int TotalMessages { get; set; }
public int TotalNotifications { get; set; }
public int TotalCampaigns { get; set; }
public int TotalFeedbacks { get; set; }
}
Conclusion
With these views created for each controller, you now have a complete set of Razor views that correspond to the actions in your ASP.NET MVC controllers. Each view is structured to allow users to perform CRUD operations on the respective models, providing a user-friendly interface for managing data in your application. You can further customize these views to fit your application's design and functionality requirements.
Creating a Dashboard Page
Creating a dashboard page in an ASP.NET MVC application involves aggregating data from various models and displaying it in a user-friendly format. Below, I will outline how to create a simple dashboard that consolidates data from the different repositories we have created.
Step 1: Create a Dashboard ViewModel
First, we need a ViewModel that will hold the consolidated data for the dashboard. This ViewModel will include properties for the various data points we want to display.
ViewModels/DashboardViewModel.cs
public class DashboardViewModel
{
public int TotalUsers { get; set; }
public int TotalRoles { get; set; }
public int TotalProperties { get; set; }
public int TotalAppointments { get; set; }
public int TotalPayments { get; set; }
public int TotalDocuments { get; set; }
public int TotalReports { get; set; }
public int TotalMessages { get; set; }
public int TotalNotifications { get; set; }
public int TotalCampaigns { get; set; }
public int TotalFeedbacks { get; set; }
}
Step 2: Create a Dashboard Controller
Next, we will create a controller that will fetch the data from the repositories and populate the DashboardViewModel.
Controllers/DashboardController.cs
public class DashboardController : Controller
{
private readonly UserRepository _userRepository;
private readonly RoleRepository _roleRepository;
private readonly PropertyRepository _propertyRepository;
private readonly AppointmentRepository _appointmentRepository;
private readonly PaymentRepository _paymentRepository;
private readonly DocumentRepository _documentRepository;
private readonly ReportRepository _reportRepository;
private readonly MessageRepository _messageRepository;
private readonly NotificationRepository _notificationRepository;
private readonly CampaignRepository _campaignRepository;
private readonly FeedbackRepository _feedbackRepository;
public DashboardController(
UserRepository userRepository,
RoleRepository roleRepository,
PropertyRepository propertyRepository,
AppointmentRepository appointmentRepository,
PaymentRepository paymentRepository,
DocumentRepository documentRepository,
ReportRepository reportRepository,
MessageRepository messageRepository,
NotificationRepository notificationRepository,
CampaignRepository campaignRepository,
FeedbackRepository feedbackRepository)
{
_userRepository = userRepository;
_roleRepository = roleRepository;
_propertyRepository = propertyRepository;
_appointmentRepository = appointmentRepository;
_paymentRepository = paymentRepository;
_documentRepository = documentRepository;
_reportRepository = reportRepository;
_messageRepository = messageRepository;
_notificationRepository = notificationRepository;
_campaignRepository = campaignRepository;
_feedbackRepository = feedbackRepository;
}
public IActionResult Index()
{
var dashboardViewModel = new DashboardViewModel
{
TotalUsers = _userRepository.GetAllUsers().Count(),
TotalRoles = _roleRepository.GetAllRoles().Count(),
TotalProperties = _propertyRepository.GetAllProperties().Count(),
TotalAppointments = _appointmentRepository.GetAllAppointments().Count(),
TotalPayments = _paymentRepository.GetAllPayments().Count(),
TotalDocuments = _documentRepository.GetAllDocuments().Count(),
TotalReports = _reportRepository.GetAllReports().Count(),
TotalMessages = _messageRepository.GetAllMessages().Count(),
TotalNotifications = _notificationRepository.GetAllNotifications().Count(),
TotalCampaigns = _campaignRepository.GetAllCampaigns().Count(),
TotalFeedbacks = _feedbackRepository.GetAllFeedbacks().Count()
};
return View(dashboardViewModel);
}
}
Step 3: Create the Dashboard View
Now, we will create a view that will display the data from the DashboardViewModel.
Views/Dashboard/Index.cshtml
@model YourNamespace.ViewModels.DashboardViewModel
<h2>Dashboard</h2>
<div class="row">
<div class="col-md-3">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Users</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalUsers</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Roles</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalRoles</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-info mb-3">
<div class="card-header">Total Properties</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalProperties</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-warning mb-3">
<div class="card-header">Total Appointments</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalAppointments</h5>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="card text-white bg-danger mb-3">
<div class="card-header">Total Payments</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalPayments</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-secondary mb-3">
<div class="card-header">Total Documents</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalDocuments</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-dark mb-3">
<div class="card-header">Total Reports</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalReports</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-light mb-3">
<div class="card-header">Total Messages</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalMessages</h5>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Notifications</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalNotifications</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Campaigns</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalCampaigns</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-info mb-3">
<div class="card-header">Total Feedbacks</div>
<div class="card-body">
<h5 class="card-title">@Model.TotalFeedbacks</h5>
</div>
</div>
</div>
</div>
Step 4: Update the Routing
Make sure to add a route for the dashboard in your Startup.cs or Program.cs file, depending on your ASP.NET version.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "dashboard",
pattern: "Dashboard",
defaults: new { controller = "Dashboard", action = "Index" });
});
Conclusion
With these steps, you have created a dashboard page that consolidates data related to your project. The dashboard displays key metrics in a visually appealing format using Bootstrap cards. You can further enhance the dashboard by adding charts, graphs, or other visual elements to represent the data more effectively.