Home
Relevant source files
The following files were used as context for generating this wiki page:- Program.cs
- Data/UserDBContext.cs
- Migrations/UserDBContextModelSnapshot.cs
- Controllers/Login/UserController.cs
- Controllers/LoadProduct/ProductController.cs
- Controllers/Order/OrderController.cs
- Configuration/UserConfiguration.cs
- Configuration/ProductConfiguration.cs
- Configuration/OrderConfiguration.cs
- Properties/launchSettings.json
This document provides a technical overview of the WEBAPI project, an ASP.NET Core application designed to serve as the backend for an e-commerce platform. The API manages core functionalities including user authentication, product catalog management, and order processing. It leverages Entity Framework Core for data access against a SQL Server database and exposes a RESTful interface for client applications.
The system is built with a layered architecture, separating concerns into controllers for handling HTTP requests, services for business logic, and a data access layer using the repository pattern with DbContext. The project is configured to support standard development practices, including dependency injection, Swagger for API documentation, and CORS for cross-origin requests.
Project Startup and Configuration
The application's entry point is Program.cs, which sets up the web application host, configures services for dependency injection, and defines the HTTP request processing pipeline.
Sources: Program.cs
Service Configuration
The following services are registered in the dependency injection container:
| Service | Configuration | Purpose |
|---|---|---|
| Controllers | AddControllers() | Registers MVC controllers. |
| JSON Serialization | AddJsonOptions(...) | Configured to ignore object cycles during serialization to prevent errors with navigation properties. |
| API Explorer | AddEndpointsApiExplorer() | Required for Swagger/OpenAPI generation. |
| Swagger | AddSwaggerGen() | Generates API documentation. |
| Database Context | AddDbContext<UserDBContext>() | Registers the EF Core UserDBContext and configures it to use SQL Server with a connection string from appsettings.json. |
| Session | AddDistributedMemoryCache(), AddSession() | Configures in-memory session storage with a 5-minute idle timeout. |
| Custom Services | AddTransient<IUserService, ...>, AddScoped<IProductService, ...>, AddScoped<IOrderService, ...> | Registers the application's business logic services with specific lifetimes. |
| HTTP Client | AddHttpClient() | Registers IHttpClientFactory for making HTTP requests. |
Sources: Program.cs:13-41
HTTP Request Pipeline
The middleware pipeline is configured to handle incoming requests. The order of middleware is critical.
This diagram shows the flow of an HTTP request through the configured middleware pipeline.
Sources: Program.cs:45-59
Launch Profiles
The application is configured to run on different profiles for development, including HTTP, HTTPS, and IIS Express. The default launch URL is set to /swagger to provide immediate access to the API documentation.
Sources: Properties/launchSettings.json:13-30
Database and Data Models
The data layer is managed by Entity Framework Core. The UserDBContext class is the central point for database interaction, defining the DbSet properties for each entity and applying model configurations.
Sources: Data/UserDBContext.cs, Migrations/UserDBContextModelSnapshot.cs
Entity Relationship Diagram
The diagram below illustrates the relationships between the core entities in the database.
This ERD shows the schema defined in the application, including primary keys, foreign keys, and relationships between tables like USER, ORDER, PRODUCT, and CATEGORY.
Sources: Migrations/UserDBContextModelSnapshot.cs, Data/UserDBContext.cs:15-39, Models/Category.cs:15, Models/Order.cs:22
Model Configuration
Entity configurations are applied in OnModelCreating to define table names, keys, property constraints, and relationships.
// Data/UserDBContext.cs
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Apply all configurations
modelBuilder.ApplyConfiguration(new UserConfiguration());
modelBuilder.ApplyConfiguration(new OrderConfiguration());
modelBuilder.ApplyConfiguration(new ProductConfiguration());
modelBuilder.ApplyConfiguration(new AdminConfiguration());
modelBuilder.ApplyConfiguration(new CategoryConfiguration());
modelBuilder.ApplyConfiguration(new OrderItemConfiguration());
// ... relationship definitions
}
Sources: Data/UserDBContext.cs:13-29
API Endpoints
The API exposes several controllers to manage different resources. All endpoints are versioned under /api/v1/.
User Management (/api/v1/user)
Handles user registration, login, and account recovery.
Sources: Controllers/Login/UserController.cs
| Method | Endpoint | Description |
|---|---|---|
POST | /register | Registers a new user. Checks for existing username and email. |
POST | /login | Authenticates a user and returns user details upon success. |
POST | /forgot-password | Initiates the password reset process by sending an email with a reset token. |
POST | /reset-password | Resets the user's password using a valid token. |
GET | / | Retrieves a list of all users. |
GET | /{id} | Retrieves a specific user by their ID. |
Login Sequence
This diagram shows the sequence of operations during a user login attempt.
Sources: Controllers/Login/UserController.cs:100-128
Product Management (/api/v1/product)
Provides CRUD operations for managing the product catalog.
Sources: Controllers/LoadProduct/ProductController.cs
| Method | Endpoint | Description |
|---|---|---|
GET | / | Retrieves a list of all products. |
GET | /new | Retrieves a list of newly added products. |
GET | /{id} | Retrieves a single product by its ID. |
POST | / | Adds a new product to the catalog. |
PUT | /{id} | Updates an existing product. |
DELETE | /{id} | Deletes a product from the catalog. |
Order Management (/api/v1/order)
Manages customer orders, including creation, retrieval, and status updates.
Sources: Controllers/Order/OrderController.cs
| Method | Endpoint | Description |
|---|---|---|
POST | / | Creates a new order with associated order items. |
GET | / | Retrieves all orders. |
GET | /{id} | Retrieves a single order by its ID. |
GET | /user/{CustomerID} | Retrieves all orders for a specific customer. |
PUT | /{id} | Updates an entire order. |
PATCH | /{id} | Partially updates an order's status, address, and delivery method. |
DELETE | /{id} | Deletes an order. |
Create Order Sequence
This diagram illustrates the process of creating a new order via the API.
Sources: Controllers/Order/OrderController.cs:23-60, Dtos/CreateOrderRequest.cs