Skip to content

abdallagaber/MVC_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MVC Project - E-Commerce Application

A comprehensive ASP.NET Core MVC e-commerce application built with .NET 10, Entity Framework Core, and ASP.NET Identity for user authentication and management.

🎯 Project Overview

This is a full-featured e-commerce web application that allows users to browse products, manage shopping carts, place orders, and manage their profiles. The application implements a hierarchical category system, user authentication, and order management.

πŸ—οΈ Architecture

Technology Stack

  • Framework: ASP.NET Core with .NET 10
  • Database: SQL Server with Entity Framework Core
  • Authentication: ASP.NET Identity
  • Pattern: MVC (Model-View-Controller)
  • Session Management: ASP.NET Core Session

Project Structure

MVC_Project/
β”œβ”€β”€ Entities/                          # Core domain models
β”‚   β”œβ”€β”€ AppUser.cs                    # Extended Identity user
β”‚   β”œβ”€β”€ Product.cs                    # Product catalog
β”‚   β”œβ”€β”€ Category.cs                   # Category hierarchy
β”‚   β”œβ”€β”€ Order.cs                      # Customer orders
β”‚   β”œβ”€β”€ OrderItem.cs                  # Order line items
β”‚   └── Address.cs                    # Shipping addresses
β”œβ”€β”€ Controllers/                       # MVC controllers
β”‚   β”œβ”€β”€ CatalogController.cs          # Product browsing & search
β”‚   β”œβ”€β”€ AccountController.cs          # Authentication & registration
β”‚   β”œβ”€β”€ ProfileController.cs          # User profile management
β”‚   └── HomeController.cs             # Home page
β”œβ”€β”€ Views/                             # Razor views
β”œβ”€β”€ Models/ViewModels/                 # View model objects
β”œβ”€β”€ Infrastructure/
β”‚   β”œβ”€β”€ Data/
β”‚   β”‚   └── AppDbContext.cs           # EF Core database context
β”‚   └── Configurations/               # EF Core entity configurations
β”œβ”€β”€ Repo/                             # Data access layer
β”‚   β”œβ”€β”€ UnitOfWork.cs                # Unit of Work pattern
β”‚   β”œβ”€β”€ EntityRepo.cs                # Generic repository
β”‚   β”œβ”€β”€ ProductRepo.cs               # Product-specific queries
β”‚   β”œβ”€β”€ CategoryRepo.cs              # Category-specific queries
β”‚   └── ...
└── Migrations/                        # Database migrations

πŸ“‹ Core Entities

AppUser

Extended ASP.NET Identity user with:

  • Full name storage
  • Multiple shipping addresses
  • Order history

Product

E-commerce product representation:

  • Name and SKU (Stock Keeping Unit)
  • Pricing with decimal precision
  • Stock quantity tracking
  • Active/inactive status
  • Category association
  • Creation timestamp

Category

Hierarchical category system:

  • Parent-child category relationships
  • Supports unlimited nesting levels
  • Associated products

Order

Customer order management:

  • Order number and status tracking
  • Associated user and shipping address
  • Order date and total amount
  • Collection of order items
  • Decimal precision for amounts

OrderItem

Individual line items in orders:

  • Product and order references
  • Unit price and quantity
  • Computed line total

Address

Shipping address management:

  • Complete address fields (country, city, street, zip)
  • Multiple addresses per user
  • Default address flag
  • Associated orders

πŸ”‘ Key Features

1. Product Catalog

  • Browse products with pagination
  • Search by product name or SKU
  • Sort by name, price, or popularity
  • Filter by category with hierarchical support
  • Advanced filtering with descendant categories

2. User Authentication

  • User registration with email verification
  • Secure login/logout
  • Role-based access control (User roles)
  • Password security

3. User Profile Management

  • View and edit profile information
  • Manage multiple shipping addresses
  • Set default address
  • Order history tracking

4. Shopping Cart

  • Session-based cart storage
  • Add/remove products
  • Quantity adjustment

5. Order Management

  • Create orders from cart
  • Order status tracking
  • Order history for users
  • Order number generation

πŸ—„οΈ Database Configuration

Connection String

"DefaultConnection": "Data Source=.;Initial Catalog=MVC_Project;Integrated Security=True;TrustServerCertificate=True"

Database Provider

  • SQL Server with local database or network instance support
  • Entity Framework Core for ORM

πŸš€ Getting Started

Prerequisites

  • .NET 10 SDK
  • SQL Server (local or remote)
  • Visual Studio 2026 (or compatible IDE)

Setup Instructions

  1. Clone the repository
git clone https://github.com/abdallagaber/MVC_Project.git
  1. Navigate to project directory
cd MVC_Project
  1. Update database connection

    • Edit appsettings.json
    • Update DefaultConnection if needed
  2. Apply database migrations

dotnet ef database update
  1. Run the application
dotnet run
  1. Access the application
    • Open browser to https://localhost:5001 (or configured port)
    • Default route: Catalog Index

πŸ“¦ Dependencies

NuGet Packages (Key)

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.AspNetCore.Session

πŸ›οΈ Design Patterns

Unit of Work Pattern

  • IUnitOfWork interface for transaction management
  • Provides access to all repositories
  • Ensures data consistency across operations

Repository Pattern

  • Generic EntityRepo<T> base repository
  • Specialized repositories for complex queries:
    • ProductRepo: Product-specific queries and active product filtering
    • CategoryRepo: Hierarchical category queries
    • AddressRepo: User address management

Dependency Injection

  • Constructor injection for services
  • Scoped lifetime for repositories and DbContext
  • Configured in Program.cs

πŸ”’ Security Features

  • ASP.NET Identity for authentication
  • Password hashing and validation
  • Entity Framework Core parameterized queries (SQL injection protection)
  • Authorization attributes on protected controllers
  • Session-based state management

πŸ—‚οΈ Configuration

Program.cs Setup

// Database context
builder.Services.AddDbContext<AppDbContext>(options =>
{
	options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});

// Unit of Work
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();

// Identity
builder.Services.AddIdentity<AppUser, IdentityRole>(options =>
{
	options.User.RequireUniqueEmail = true;
})
	.AddEntityFrameworkStores<AppDbContext>();

// Sessions
builder.Services.AddSession();

πŸ“Š Data Flow

  1. Catalog Browsing

    • User accesses Catalog/Index
    • CatalogController queries products through UnitOfWork
    • Results paginated and displayed with filters/sorting
  2. User Registration/Login

    • User submits registration form
    • AccountController uses UserManager for identity operations
    • User assigned "User" role
  3. Order Creation

    • Cart data retrieved from session
    • OrderController creates Order and OrderItems
    • Order associated with user and shipping address
    • UnitOfWork ensures data consistency

πŸ”„ Database Migrations

The project uses Entity Framework Core Code-First approach with migrations:

  • Located in Migrations/ folder
  • Initial migration: 20260310204100_InitialCreate.cs
  • Run migrations with: dotnet ef database update

πŸ› οΈ Development

Common Tasks

Add new entity:

  1. Create entity class in Entities/
  2. Add DbSet to AppDbContext
  3. Add configuration if needed in Configurations/
  4. Create migration: dotnet ef migrations add MigrationName
  5. Update database: dotnet ef database update

Add new repository:

  1. Create repository class extending EntityRepo<T>
  2. Add interface to IUnitOfWork
  3. Register in UnitOfWork implementation
  4. Inject through DI container

πŸ“ Logging

Logging configuration in appsettings.json:

"Logging": {
	"LogLevel": {
		"Default": "Information",
		"Microsoft.AspNetCore": "Warning"
	}
}

πŸ”— Repository

πŸŽ“ Learning Context

This project is developed as an educational exercise to demonstrate:

  • ASP.NET Core MVC fundamentals
  • Entity Framework Core with SQL Server
  • ASP.NET Identity integration
  • Repository and Unit of Work patterns
  • Hierarchical data management
  • E-commerce domain modeling
  • Session-based state management

🀝 Contributing

This is an educational project. For improvements or bug fixes, please create issues or pull requests on the GitHub repository.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors