ASP.NET Core MVC Intermediate

Build a complete task manager app from start to finish

This final project ties the course together by building a small but complete task manager: sign-in, a database with EF Core, list pages with search and paging, validated forms, AJAX, tests and deployment. Each step lists the lessons to revisit, so you can build it on your own.

TaskBoard from top to bottom
  1. Razor viewsList, forms, partial rows, view component
  2. Controllers[Authorize], view models, anti-forgery
  3. EF CoreAppDbContext, migrations, owner filter
  4. SQL ServerTasks and Identity tables with indexes
  5. DeliveryTests, Docker, GitHub Actions, Azure

What you will build

TaskBoard: users sign up and manage their own tasks. Each task has a title, notes, due date, priority and status. The list page supports search, filters, sorting and paging; a checkbox marks tasks done without a page reload; an overdue count shows on every page. Users can only ever see their own tasks.

The point is not the features but doing each part properly, as a real app would.

Step by step

  • 1. Create the project with dotnet new mvc --auth Individual and run it (lessons: getting started, Visual Studio walkthrough).
  • 2. Add the TaskItem entity, a migration and the database (EF Core course: DbContext, migrations).
  • 3. Build Create, Edit and Delete with view models, validation and anti-forgery (view models, model validation, client-side validation).
  • 4. Build the list page with search, sort and paging (list pages, async actions).
  • 5. Mark done with fetch and a partial view; show the overdue count with a view component (AJAX, view components).
  • 6. Add tests, a Dockerfile and a GitHub Actions workflow, then deploy (testing, Docker, CI/CD, Azure).

The core of the app

The entity, and a controller that always filters by the signed-in user. Filtering by owner on every query is what stops users reading each other's tasks.

C#
public class TaskItem
{
    public int Id { get; set; }
    [Required, StringLength(200)] public string Title { get; set; } = "";
    [StringLength(2000)] public string? Notes { get; set; }
    public DateOnly? DueOn { get; set; }
    public Priority Priority { get; set; } = Priority.Normal;
    public bool IsDone { get; set; }
    public string OwnerId { get; set; } = "";       // IdentityUser.Id
}
public enum Priority { Low, Normal, High }

[Authorize]
public class TasksController(AppDbContext db) : Controller
{
    private string Me => User.FindFirstValue(ClaimTypes.NameIdentifier)!;
    private IQueryable<TaskItem> MyTasks => db.Tasks.Where(t => t.OwnerId == Me);

    public async Task<IActionResult> Index([FromQuery] TaskQuery q, CancellationToken ct)
    {
        var query = MyTasks.AsNoTracking();
        if (!string.IsNullOrWhiteSpace(q.Search)) query = query.Where(t => t.Title.Contains(q.Search));
        if (q.OnlyOpen) query = query.Where(t => !t.IsDone);
        query = q.Sort == "due" ? query.OrderBy(t => t.DueOn ?? DateOnly.MaxValue).ThenBy(t => t.Id)
                                : query.OrderByDescending(t => t.Priority).ThenBy(t => t.Id);
        var total = await query.CountAsync(ct);
        var items = await query.Skip((q.Page - 1) * 20).Take(20).ToListAsync(ct);
        return View(new TaskPage(items, q, total));
    }

    [HttpPost, ValidateAntiForgeryToken]
    public async Task<IActionResult> ToggleDone(int id, CancellationToken ct)
    {
        var task = await MyTasks.SingleOrDefaultAsync(t => t.Id == id, ct);
        if (task is null) return NotFound();             // also for other users' tasks
        task.IsDone = !task.IsDone;
        await db.SaveChangesAsync(ct);
        return PartialView("_TaskRow", task);
    }
}

A test that matters

Test the rule that protects users: one user cannot change another user's task.

C#
[Fact]
public async Task Cannot_toggle_someone_elses_task()
{
    await using var db = fixture.CreateContext();
    db.Tasks.Add(new TaskItem { Id = 1, Title = "Private", OwnerId = "alice" });
    await db.SaveChangesAsync();

    var controller = new TasksController(db) { ControllerContext = ContextFor(userId: "bob") };
    var result = await controller.ToggleDone(1, CancellationToken.None);

    Assert.IsType<NotFoundResult>(result);
}

Finish line checklist

  • Every query for tasks goes through MyTasks; no action reads by id alone.
  • All POST actions have [ValidateAntiForgeryToken]; all edit forms use view models.
  • Errors show a friendly page in production; secrets live in user secrets or Key Vault.
  • The list stays fast with 10,000 tasks (index on OwnerId, IsDone, DueOn).
  • CI runs tests on every push, and the deployed site uses HTTPS and a managed identity.

Interview question

In a multi-user app, how do you make sure users can only see and change their own records?

Store an owner id on each record from the signed-in user's claims, never from form input, and route every query through a base query filtered by that owner, such as MyTasks => db.Tasks.Where(t => t.OwnerId == userId), or an EF Core global query filter. Return NotFound when a record is missing or belongs to someone else, and add tests that try to access another user's data.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.