Cinema-NLayer-MVC is a web application built using ASP.NET Core MVC with N-layer architecture, allowing users to browse movie listings, select films, and purchase tickets online.
- Backend: ASP.NET Core 8 (MVC), Entity Framework Core, Identity, AutoMapper, FluentValidation
- Frontend: Razor Views, Bootstrap
- Database: SQL Server
- Architecture: N-layer (WebApp, BusinessLogic(BLL), DataAccess(DAL)
The project follows an N-layer architecture to ensure separation of concerns and maintainability.
π Cinema-NLayer-MVC
βββ π Cinema.WebApp # Presentation Layer (MVC, UI)
β βββ wwwroot # Static files (CSS, JS, images)
β βββ Controllers # MVC controllers handling requests
β βββ ViewModels # View-specific data models
β βββ Views # Razor views for the UI
β βββ appsettings.json # Configuration file
β βββ Program.cs # Application entry point
β
βββ π Cinema.BLL # Business Logic Layer
β βββ Helpers # Utility classes and helper methods
β β βββ ApplicationProfile.cs # Mapping or custom application logic
β βββ Services # Core business services
β βββ Interfaces # Abstractions for business services
β βββ Validators # Contains classes that validate models and DTOs
β βββ ServiceExtensions.cs # Extension methods for business logic services
β βββ DTOs # Data Transfer Objects
β
βββ π Cinema.DAL # Data Access Layer
βββ Dependencies # Additional dependencies or third-party integrations
βββ Analyzers # Code analyzers and diagnostics
βββ Repositories # Repository pattern implementations
βββ Packages # NuGet or package references
βββ Configurations # Entity Framework configurations
βββ Data # EF Core DbContext
β βββ CinemaDbContext.cs # Main EF Core DbContext
β βββ SeedDataExtensions.cs # Database seeding logic
βββ Entities # Database entity models
βββ Interfaces # Abstractions for IRepository and IEntity
βββ Migrations # EF Core migrations
βββ ServiceExtensions.cs # Extension methods for data access services
Clone the project to your local machine using Git:
git clone https://github.com/KobMiles/Cinema-Nlayer-MVC.git
cd Cinema-NLayer-MVCEnsure that SQL Server is installed on your system. You can use SQL Server Express or SQL Server LocalDB.
You can download and install it from the official Microsoft documentation: Install LocalDB β Microsoft Docs
Your project requires a connection string to establish a connection with the database. You have two options for storing it:
1οΈβ£Using appsettings.json (for general use)
-
Open or create your appsettings.json file.
-
Under ConnectionStrings, add your connection string. For a local database in Visual Studio, you can use the example below:
{ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=CinemaDB;Trusted_Connection=True;MultipleActiveResultSets=true" } } -
Ensure your project is set up to read DefaultConnection from this section (for instance, by referencing Configuration.GetConnectionString("DefaultConnection") in your code).
-
Optional: If you already have your own database, replace the above connection string with your own.
2οΈβ£Using UserSecrets (recommended for security π)
To protect connection strings and other credentials, store them in **UserSecrets** instead of appsettings.json. Hereβs how:-
Right-click WebApp project in Solution Explorer and select Manage User Secrets.
-
A secrets.json file will open. Add your connection string there:
{ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=CinemaDB;Trusted_Connection=True;MultipleActiveResultSets=true" } } -
This file is kept out of source control automatically.
-
Open a terminal in your project folder.
-
Initialize user secrets (if not done already):
dotnet user-secrets init
-
Add your connection string using:
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Server=(localdb)\\MSSQLLocalDB;Database=CinemaDB;Trusted_Connection=True;MultipleActiveResultSets=true"
-
The secrets.json file is updated accordingly (but not committed to source control).
The provided connection strings are designed to automatically create a local database using SQL Server LocalDB. To use this feature, ensure that LocalDB is installed on your system. You can download and install it from the official Microsoft documentation:
π Install LocalDB β Microsoft Docs
If you prefer to connect to an existing database instead of creating a local one, replace the default connection string with your own. Hereβs an example of a custom connection string:
{
"ConnectionStrings": {
"DefaultConnection": "Server=YOUR_SERVER;Database=YOUR_DATABASE;User Id=YOUR_USER;Password=YOUR_PASSWORD;MultipleActiveResultSets=true"
}
}Replace YOUR_SERVER, YOUR_DATABASE, YOUR_USER, and YOUR_PASSWORD with your actual database credentials.
By configuring your connection string correctly, you ensure seamless integration with your chosen SQL Server instance. π
Run the following command to apply migrations and create the database schema:
dotnet ef database update --project Cinema.DAL --startup-project Cinema.WebAppIf migrations are missing, create one:
dotnet ef migrations add InitialCreate --project Cinema.DAL --startup-project Cinema.WebApp
dotnet ef database update --project Cinema.DAL --startup-project Cinema.WebAppStart the ASP.NET Core MVC application:
dotnet run --project Cinema.WebAppAlternatively, if using Visual Studio:
- Open the Cinema-NLayer-MVC.sln solution.
- Set Cinema.WebApp as the startup project.
- Press F5 to run in debug mode.
Once started, the app will be accessible at:
- http://localhost:5145 (For HTTP)
- https://localhost:7129 (For HTTPS)
This project uses the following dependencies:
| Package | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
ORM for database interactions |
Microsoft.EntityFrameworkCore.SqlServer |
SQL Server provider for EF Core |
Microsoft.AspNetCore.Identity |
Authentication & Identity management |
AutoMapper |
Object-to-object mapping |
FluentValidation |
Model validation |
If any dependencies are missing, install them with:
dotnet restore