An ASP.NET Core Web API for projects and their tasks. It uses a layered design: a
class library (TaskTracker.Core) holds the entities, DTOs, mappings and repository interfaces, and the
web project (TaskTracker.Api) holds EF Core, the repositories and the controllers. Some logic lives in
the database itself: a view, a stored procedure and a trigger, all created through EF Core migrations.
Projects and tasks
- List projects; get one project together with its tasks.
- Create, rename and delete projects.
- A project that still has tasks cannot be deleted. The API answers
409 Conflictinstead of failing with a database error. - Add a task to a project. The parent project always comes from the URL, never from the request body.
- Mark a task done or not done. A task can only be changed through the project it belongs to.
- Validate all input (
400 Bad Requestwith field-level messages).
Reporting (database objects) 7. When a task is marked done, record the completion time; clear it if the task is reopened. This must hold even if the row is changed outside the API, so a trigger does it, not C# code. 8. Report each project's progress: total tasks, completed tasks and percentage, from a view. 9. List overdue tasks as of a given date, with days overdue, from a stored procedure.
.NET 10 · ASP.NET Core (controllers) · EF Core 10 (code-first migrations) · SQL Server 2022 in Docker ·
T-SQL (view, stored procedure, trigger) · OpenAPI + Scalar · dotnet user-secrets
TaskTracker/
├── TaskTracker.slnx
├── dotnet-tools.json pins the dotnet-ef tool version
├── TaskTracker.Core/ class library, no ASP.NET Core or EF Core dependency
│ ├── Entities/ Project, TaskItem
│ ├── Dtos/ request and response shapes
│ ├── Mappings/ entity <-> DTO extension methods
│ ├── Reports/ ProjectProgress (view row), OverdueTask (stored procedure row)
│ └── Repositories/ IProjectRepository, IReportRepository
└── TaskTracker.Api/ web project, references TaskTracker.Core
├── Data/TaskTrackerContext.cs EF Core model: keys, lengths, delete rule, view mapping, trigger
├── Repositories/ EF Core implementations of the Core interfaces
├── Controllers/ ProjectsController, ReportsController
├── Migrations/ InitialCreate, AddReportingObjects
└── Program.cs dependency injection setup
All three are created by the AddReportingObjects migration and removed by its Down method.
| Object | Name | Purpose | Used by |
|---|---|---|---|
| Trigger | dbo.trg_TaskItems_SetCompletedAt |
AFTER INSERT, UPDATE on TaskItems: sets CompletedAtUtc when IsDone becomes 1, clears it when it becomes 0 |
PATCH /api/projects/{id}/tasks/{taskId} |
| View | dbo.vw_ProjectProgress |
One row per project with total, completed and percent complete | GET /api/reports/project-progress (EF keyless entity) |
| Stored procedure | dbo.usp_GetOverdueTasks @AsOfDate |
Open tasks with a due date before @AsOfDate, oldest first |
GET /api/reports/overdue-tasks (Database.SqlQuery) |
The EF mapping declares the task-table trigger so SQL Server writes omit the incompatible OUTPUT clause.
CompletedAtUtc is database-generated and is read as UTC. The reporting migration runs each schema definition in
its own SQL batch and backfills completion timestamps for existing completed tasks.
The application requires a reachable SQL Server instance and a connection string stored with dotnet user-secrets.
The container commands below require Docker and an x86-64 Linux environment. Microsoft does not support SQL Server containers
under Apple Silicon emulation; --platform linux/amd64 does not remove that limitation.
See SQL Server container requirements.
On an ARM Mac, the API can connect to SQL Server hosted on a supported machine instead.
- Start SQL Server (the password must have 8+ characters with upper case, lower case and digits):
docker run -d --name sql --platform linux/amd64 -e ACCEPT_EULA=Y -e 'MSSQL_SA_PASSWORD=<your-password>' \ -p 127.0.0.1:1433:1433 mcr.microsoft.com/mssql/server:2022-latest - Restore the EF tool, store the connection string and create the database:
dotnet tool restore cd TaskTracker.Api dotnet user-secrets set "ConnectionStrings:TaskTracker" "Server=localhost,1433;Database=TaskTracker;User Id=sa;Password=<your-password>;TrustServerCertificate=True" dotnet ef database update
- Run it and open http://localhost:5021/scalar/v1:
dotnet run
To see the SQL the migrations run, use dotnet ef migrations script. To undo the reporting objects,
use dotnet ef database update InitialCreate.
| Method | Route | Success | Errors |
|---|---|---|---|
| GET | /api/projects |
200, summaries | |
| GET | /api/projects/{id} |
200, project with tasks | 404 |
| POST | /api/projects |
201 | 400 |
| PUT | /api/projects/{id} |
204 | 400, 404 |
| DELETE | /api/projects/{id} |
204 | 404, 409 if it has tasks |
| POST | /api/projects/{id}/tasks |
201, task | 400, 404 |
| PATCH | /api/projects/{id}/tasks/{taskId} |
200, task (with completedAtUtc) |
400, 404 |
| GET | /api/reports/project-progress |
200 | |
| GET | /api/reports/overdue-tasks?asOf=YYYY-MM-DD |
200 (defaults to today, UTC) | 400 for a bad date |
dotnet test TaskTracker.slnxThe tests use ASP.NET Core's test host and EF Core's in-memory provider; SQL Server is not needed to run them. They verify HTTP routing, validation and application behavior. They do not verify SQL Server's SQL execution, relational constraints or concurrency behavior. Tests cover parent-child routing, deletion rules, status validation and SQL Server model metadata. The view, trigger and stored procedure require the live checks below.
Manual acceptance checks, run in order against a freshly migrated database. Each request is in TaskTracker.Api/TaskTracker.Api.http.
| # | Check | Steps | Expected result |
|---|---|---|---|
| 1 | List | GET /api/projects |
200; Onboarding guide and Website redesign |
| 2 | Details | GET /api/projects/1 |
200; two tasks; task 1 is done and has a completedAtUtc (backfill) |
| 3 | Add task | POST /api/projects/1/tasks with a title |
201; isDone false, completedAtUtc null |
| 4 | Trigger: complete | PATCH /api/projects/1/tasks/2 with {"isDone": true} |
200; completedAtUtc now has a timestamp |
| 5 | Trigger: reopen | Same request with {"isDone": false} |
200; completedAtUtc is null again |
| 6 | Wrong parent | PATCH /api/projects/2/tasks/1 with {"isDone": true} |
404 (task 1 belongs to project 1) |
| 7 | Validation | PATCH /api/projects/1/tasks/2 with {} |
400; errors.IsDone |
| 8 | Delete rule | DELETE /api/projects/1 |
409 with an explanation |
| 9 | Delete | DELETE /api/projects/2 |
204 |
| 10 | View | GET /api/reports/project-progress |
One row per remaining project; counts and percentage match its tasks |
| 11 | Stored procedure | GET /api/reports/overdue-tasks?asOf=2027-01-01 |
Open tasks due before that date; Pick a colour palette shows daysOverdue: 17 |
| 12 | Trigger outside the API | sqlcmd ... -d TaskTracker -Q "UPDATE TaskItems SET IsDone = 1 WHERE Id = 2; SELECT Id, IsDone, CompletedAtUtc FROM TaskItems" |
Task 2's CompletedAtUtc is set even though the API wasn't involved |
| 13 | Objects exist | sqlcmd ... -d TaskTracker -Q "SELECT name, type_desc FROM sys.objects WHERE name LIKE 'vw[_]%' OR name LIKE 'usp[_]%' OR name LIKE 'trg[_]%'" |
One VIEW, one SQL_STORED_PROCEDURE, one SQL_TRIGGER |
Inspired by laxmikant-geek/implement-repository-pattern-with-aspnet-core-web-api. This is an independent rewrite, not a copy of that code.