Skip to content

Repository files navigation

Invoice Management System

Invoice Management System is an ASP.NET Core Web API developed using .NET 8 and SQL Server.

Features

  • JWT-based User Authentication
  • Password Hashing
  • Role-Based Permission System with database-driven permissions
  • Invoice Create, View, Update and Delete
  • Auto-generated Invoice Numbers
  • Pagination
  • Search
  • Sorting
  • Soft Delete
  • Global Exception Handling
  • Input Validation
  • EF Core Code First Migrations
  • Dependency Injection
  • Repository and Service Pattern
  • Async/Await

Technologies Used

  • ASP.NET Core Web API (.NET 8)
  • Entity Framework Core
  • SQL Server
  • JWT Authentication
  • Swagger / OpenAPI

Project Structure

  • Controllers - API endpoints
  • Services - Business logic
  • Repositories - Data access logic
  • Interfaces - Service and repository contracts
  • Models - Database entities
  • DTOs - Request and response models
  • Filters - Permission authorization
  • Middleware - Global exception handling
  • Data - EF Core DbContext
  • Migrations - Database migrations

Database Setup

This project uses Entity Framework Core Code First.

1. Configure Connection String

Update appsettings.json:

"ConnectionStrings": {
  "dbcs": "YOUR_CONNECTION_STRING"
}

Example using Windows Authentication:

Server=YOUR_SERVER_NAME;Database=InvoiceManagementDB;Trusted_Connection=True;TrustServerCertificate=True;

2. Configure JWT Secret

Update the JWT key in appsettings.json:

"Jwt": {
  "Key": "YOUR_SECRET_KEY_MINIMUM_32_CHARACTERS",
  "Issuer": "InvoiceManagementSystem",
  "Audience": "InvoiceManagementSystemUsers",
  "ExpiryMinutes": 60
}

Use a secure random secret key of at least 32 characters.

3. Create Database

Open Package Manager Console and run:

Update-Database

EF Core migrations will create the required database tables and seed the initial roles and permissions.

Seeded Roles

Admin

Admin has the following permissions:

  • ViewInvoice
  • CreateInvoice
  • UpdateInvoice
  • DeleteInvoice

User

User has:

  • ViewInvoice

Authentication

Register a user using:

POST /api/Auth/register

Login using:

POST /api/Auth/login

The Login API returns a JWT token.

Use the token through Swagger's Authorize option to access protected endpoints.

Invoice APIs

POST   /api/Invoice
GET    /api/Invoice
GET    /api/Invoice/{id}
PUT    /api/Invoice/{id}
DELETE /api/Invoice/{id}

The GET endpoint supports pagination, search and sorting through query parameters.

Example:

GET /api/Invoice?pageNumber=1&pageSize=10&search=Amit&sortBy=amount&sortDescending=false

Permission Behaviour

A valid JWT token is required for Invoice APIs.

Admin users can create, view, update and delete invoices.

Normal users have ViewInvoice permission only.

Requests without valid authentication return 401 Unauthorized.

Authenticated users without the required permission return 403 Forbidden.

Running the Application

  1. Clone or download the repository.
  2. Open the solution in Visual Studio.
  3. Configure the SQL Server connection string.
  4. Configure a secure JWT secret key.
  5. Run Update-Database.
  6. Build and run the application.
  7. Open Swagger to test the APIs.

About

Invoice Management System Web API using ASP.NET Core, EF Core, JWT Authentication and Database-Driven Permissions

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages