Skip to content

robbevanhalst-dev/dotnet-aspnetcore-task-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Task Management API β€” ASP.NET Core Web API

Task Management API

A professional, production-ready ASP.NET Core Web API for managing tasks and users, built with Clean Architecture principles.
This project demonstrates modern backend development practices using .NET 9, Entity Framework Core, SQL Server LocalDB, and comprehensive error handling.

.NET C# Entity Framework SQL Server License

Portfolio Project - Built to showcase enterprise-level .NET development skills for job applications


Project Goal

Build a production-style RESTful Web API while applying:

  • Clean Architecture with clear layer separation
  • Repository Pattern for data access abstraction
  • SOLID principles and separation of concerns
  • DTO-based API communication for clean data contracts
  • FluentValidation for robust input validation
  • Global Exception Middleware for centralized error handling
  • Async/await throughout the entire application
  • Swagger/OpenAPI for comprehensive API documentation

Architecture

The solution follows Clean Architecture with the following structure:

TaskManagement.sln
- TaskManagement.Api            (Presentation / API Layer)
- TaskManagement.Application    (Business Logic Layer)
- TaskManagement.Domain         (Core Domain Models)
- TaskManagement.Infrastructure (Data Access / EF Core)

Layer Responsibilities

API Layer (TaskManagement.Api)

  • RESTful Controllers (TasksController, UsersController)
  • HTTP endpoints with proper status codes
  • Global Exception Middleware
  • Swagger/OpenAPI documentation
  • Request/Response models
  • Dependency Injection configuration

Application Layer (TaskManagement.Application)

  • Business logic services (TaskService, UserService)
  • Service interfaces (ITaskService, IUserService)
  • DTOs (Data Transfer Objects)
  • Repository interfaces (ITaskRepository, IUserRepository)
  • FluentValidation validators

Domain Layer (TaskManagement.Domain)

  • Core entities (TaskItem, User)
  • Enums (TaskStatus)
  • Business rules
  • Zero external dependencies - pure domain logic

Infrastructure Layer (TaskManagement.Infrastructure)

  • EF Core DbContext
  • Repository implementations
  • Entity configurations
  • Database migrations
  • Data persistence logic

Features

Core Functionality

  • Full CRUD operations for Tasks and Users
  • Advanced filtering (by status, user, search term, date range)
  • FluentValidation for comprehensive input validation
  • Global Exception Middleware with structured error responses
  • Async/await throughout the entire codebase
  • Swagger UI with detailed endpoint documentation
  • SQL Server LocalDB integration with EF Core
  • Repository Pattern for clean data access

Technical Features

  • Clean Architecture with proper layer separation
  • Dependency Injection with scoped services
  • Entity Framework Core 9.0 with Code First migrations
  • Structured logging with ILogger
  • XML documentation for Swagger
  • ProducesResponseType attributes for all endpoints
  • Production/Development environment-specific error handling

Technologies Used

Technology Version Purpose
C# 13.0 Primary language
.NET 9.0 Framework
ASP.NET Core 9.0 Web API framework
Entity Framework Core 9.0 ORM for database access
SQL Server LocalDB Latest Database
FluentValidation 11.11.0 Input validation
Swashbuckle 7.2.0 Swagger/OpenAPI documentation

Database Schema

The project uses Entity Framework Core Code First approach.

Main Tables

Users

  • Id (int, PK, Identity)
  • Name (nvarchar(100), Required)
  • Email (nvarchar(255), Required, Unique Index)

TaskItems

  • Id (int, PK, Identity)
  • Title (nvarchar(200), Required)
  • Description (nvarchar(1000))
  • Status (nvarchar, stored as string: "Todo", "InProgress", "Done")
  • UserId (int, FK to Users, Required)
  • CreatedDate (datetime2, Required)

Relationships:

  • One User -> Many TaskItems (Cascade Delete)

How to Run

1 Clone Repository

git clone https://github.com/robbevanhalst-dev/dotnet-aspnetcore-task-api.git
cd dotnet-aspnetcore-task-api

2 Prerequisites

  • .NET 9 SDK
  • Visual Studio 2022 (or VS Code with C# extension)
  • SQL Server LocalDB (included with Visual Studio)

3 Restore Dependencies

dotnet restore

4 Update Database

The migrations are already created. Run:

dotnet ef database update --project src/TaskManagement.Infrastructure --startup-project src/TaskManagement.Api

Or in Package Manager Console (Visual Studio):

Update-Database

5 Run the API

In Visual Studio:

  • Set TaskManagement.Api as startup project
  • Press F5
  • Swagger UI opens automatically at https://localhost:7291

Via Command Line:

cd src/TaskManagement.Api
dotnet run

Then navigate to: https://localhost:7291


API Endpoints

Tasks Endpoints

Method Endpoint Description Auth
GET /api/tasks Get all tasks -
GET /api/tasks/{id} Get task by ID -
GET /api/tasks/filter Get filtered tasks (status, userId, searchTerm, dates) -
GET /api/tasks/user/{userId} Get tasks by user ID -
POST /api/tasks Create new task -
PUT /api/tasks/{id} Update existing task -
DELETE /api/tasks/{id} Delete task -

Users Endpoints

Method Endpoint Description Auth
GET /api/users Get all users -
GET /api/users/{id} Get user by ID -
POST /api/users Create new user -
DELETE /api/users/{id} Delete user -

Example Requests

Create User

POST /api/users
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john.doe@example.com"
}

Create Task

POST /api/tasks
Content-Type: application/json

{
  "title": "Complete project documentation",
  "description": "Write comprehensive API documentation",
  "status": 0,
  "userId": 1
}

Status Values:

  • 0 = Todo
  • 1 = InProgress
  • 2 = Done

Filter Tasks

GET /api/tasks/filter?status=1&searchTerm=documentation&userId=1

Update Task

PUT /api/tasks/1
Content-Type: application/json

{
  "title": "Updated title",
  "description": "Updated description",
  "status": 2
}

🎯 Key Concepts Demonstrated

πŸ—οΈ Architecture & Design Patterns

  • βœ… Clean Architecture - Clear separation of concerns with 4 distinct layers
  • βœ… Repository Pattern - Abstraction over data access for improved testability
  • βœ… Service Layer Pattern - Business logic encapsulation
  • βœ… Dependency Injection - Loose coupling and adherence to SOLID principles
  • βœ… DTO Pattern - Data transfer objects for clean API contracts

⚑ Best Practices

  • βœ… Async/Await - Non-blocking I/O operations for optimal performance
  • βœ… FluentValidation - Declarative validation rules, separated from business logic
  • βœ… Global Exception Middleware - Centralized error handling
  • βœ… Structured Logging - ILogger with multiple log levels
  • βœ… XML Documentation - IntelliSense and Swagger integration
  • βœ… Entity Configurations - Fluent API for EF Core mappings
  • βœ… Environment-specific settings - Development vs Production configuration

πŸ’Ž Code Quality

  • βœ… SOLID Principles - Applied throughout the entire solution
  • βœ… Single Responsibility - Each class has one clear purpose
  • βœ… Interface Segregation - Clean contracts between layers
  • βœ… Dependency Inversion - Depend on abstractions, not concrete implementations
  • βœ… DRY (Don't Repeat Yourself) - Reusable code components
  • βœ… Separation of Concerns - Each layer has its own responsibility

πŸ“Š Database & Data Access

  • βœ… Code-First Migrations - Database schema managed through C# code
  • βœ… Entity Configurations - Fluent API for relationships and constraints
  • βœ… Eager Loading - Include() statements for performance optimization
  • βœ… Connection String Management - Managed via appsettings.json

Error Handling

The API uses Global Exception Middleware for consistent error responses:

Example Error Response (404)

{
  "statusCode": 404,
  "message": "Task with id '999' was not found",
  "details": null,
  "timestamp": "2024-02-12T12:30:00.000Z",
  "path": "/api/tasks/999"
}

Example Validation Error (400)

{
  "statusCode": 400,
  "message": "One or more validation errors occurred",
  "details": "{\"Title\":[\"Title is required\"],\"Email\":[\"Invalid email format\"]}",
  "timestamp": "2024-02-12T12:30:00.000Z",
  "path": "/api/tasks"
}

Validation Rules

CreateTaskDto

  • Title: Required, max 200 characters
  • Description: Max 1000 characters
  • Status: Must be valid enum (0-2)
  • UserId: Required, must be > 0

UpdateTaskDto

  • Title: Required, max 200 characters
  • Description: Max 1000 characters
  • Status: Must be valid enum (0-2)

CreateUserDto

  • Name: Required, max 100 characters
  • Email: Required, valid email format, max 255 characters, unique

πŸš€ Future Improvements

Planned enhancements to further professionalize this project:

Priority 1 - Testability

  • Unit Tests - xUnit + Moq for services and repositories
  • Integration Tests - Test complete API flows
  • Test Coverage - Minimum 80% code coverage

Priority 2 - Security & Performance

  • Authentication & Authorization - JWT tokens with role-based access
  • Pagination - Efficient data retrieval for large datasets
  • Caching - Redis or In-Memory caching
  • Rate Limiting - API abuse prevention

Priority 3 - DevOps & Deployment

  • Docker Support - Containerization with Docker Compose
  • CI/CD Pipeline - GitHub Actions for automated testing & deployment
  • Health Checks - Endpoint monitoring
  • Logging - Structured logging with Serilog

Priority 4 - Advanced Features

  • AutoMapper - Automated DTO mappings
  • API Versioning - Backwards compatibility
  • Sorting & Advanced Filtering - More query options
  • File Uploads - Attachments for tasks
  • SignalR - Real-time notifications
  • Background Jobs - Hangfire for scheduled tasks

πŸ‘¨β€πŸ’» Author

Robbe Vanhalst
Junior .NET Developer - Actively seeking opportunities

πŸ“§ Email: robbevanhalst.dev@gmail.com
πŸ’Ό LinkedIn: Robbe Vanhalst
πŸ™ GitHub: @robbevanhalst-dev
πŸ“ Location: Kortrijk, Belgium

About This Project

This project was developed as a portfolio piece to demonstrate my .NET development skills during job applications. It showcases professional coding practices, clean architecture, and modern .NET technologies.

Skills Demonstrated:

  • βœ… Clean Architecture & SOLID Principles
  • βœ… ASP.NET Core 9 Web API Development
  • βœ… Entity Framework Core & Database Design
  • βœ… Repository Pattern & Dependency Injection
  • βœ… RESTful API Design & Best Practices
  • βœ… Error Handling & Input Validation
  • βœ… API Documentation (Swagger/OpenAPI)
  • βœ… Asynchronous Programming (async/await)

πŸ“ž Contact

Interested in collaboration or have questions about this project?
Feel free to reach out via LinkedIn or email!


⭐ If you find this project useful, please give it a star on GitHub!

About

ASP.NET Core Web API for task management built with layered architecture, EF Core and SQL Server.

Topics

Resources

License

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages