Project 1: Console Task Manager with JSON Storage

Dot NET Programming 20 min min read Updated: Nov 16, 2026 Beginner
Project 1: Console Task Manager with JSON Storage
Beginner Topic 1 of 4

What You Practice

  • Classes, enums and records
  • List<T> and LINQ
  • JSON save and load
  • Loops, switch and input validation
  • Splitting code into small classes

Step 1: Create the Project

bash dotnet new console -n TaskManager cd TaskManager

Step 2: The Model

csharp public enum Priority { Low, Medium, High } public class TodoItem { public int Id { get; set; } public required string Title { get; set; } public Priority Priority { get; set; } = Priority.Medium; public DateOnly? DueDate { get; set; } public bool IsDone { get; set; } }

Step 3: Storage Class

csharp using System.Text.Json; public class TodoStore(string path) { private static readonly JsonSerializerOptions Options = new() { WriteIndented = true }; public List<TodoItem> Load() { if (!File.Exists(path)) return []; var json = File.ReadAllText(path); return JsonSerializer.Deserialize<List<TodoItem>>(json) ?? []; } public void Save(List<TodoItem> items) { File.WriteAllText(path, JsonSerializer.Serialize(items, Options)); } }

Step 4: Business Logic

csharp public class TodoService(TodoStore store) { private readonly List<TodoItem> _items = store.Load(); public IReadOnlyList<TodoItem> All => _items; public TodoItem Add(string title, Priority priority, DateOnly? due) { var item = new TodoItem { Id = _items.Count == 0 ? 1 : _items.Max(i => i.Id) + 1, Title = title, Priority = priority, DueDate = due }; _items.Add(item); store.Save(_items); return item; } public bool Complete(int id) { var item = _items.FirstOrDefault(i => i.Id == id); if (item is null) return false; item.IsDone = true; store.Save(_items); return true; } public bool Delete(int id) { int removed = _items.RemoveAll(i => i.Id == id); if (removed > 0) store.Save(_items); return removed > 0; } public IEnumerable<TodoItem> Pending() => _items.Where(i => !i.IsDone) .OrderByDescending(i => i.Priority) .ThenBy(i => i.DueDate ?? DateOnly.MaxValue); public IEnumerable<TodoItem> Overdue() => _items.Where(i => !i.IsDone && i.DueDate < DateOnly.FromDateTime(DateTime.Today)); }

Step 5: The Menu (Program.cs)

csharp var service = new TodoService(new TodoStore("tasks.json")); while (true) { Console.WriteLine(); Console.WriteLine("1) List pending 2) Add 3) Complete 4) Delete 5) Overdue 0) Exit"); Console.Write("Choose: "); switch (Console.ReadLine()?.Trim()) { case "1": Show(service.Pending()); break; case "2": AddTask(); break; case "3": Change("Complete", service.Complete); break; case "4": Change("Delete", service.Delete); break; case "5": Show(service.Overdue()); break; case "0": return; default: Console.WriteLine("Unknown option."); break; } } void AddTask() { Console.Write("Title: "); var title = Console.ReadLine(); if (string.IsNullOrWhiteSpace(title)) { Console.WriteLine("Title is required."); return; } Console.Write("Priority (low/medium/high): "); if (!Enum.TryParse<Priority>(Console.ReadLine(), ignoreCase: true, out var priority)) priority = Priority.Medium; Console.Write("Due date (yyyy-MM-dd, Enter to skip): "); DateOnly? due = DateOnly.TryParse(Console.ReadLine(), out var d) ? d : null; var item = service.Add(title.Trim(), priority, due); Console.WriteLine($"Added task #{item.Id}"); } void Change(string action, Func<int, bool> operation) { Console.Write($"{action} which id? "); if (!int.TryParse(Console.ReadLine(), out var id)) { Console.WriteLine("Enter a number."); return; } Console.WriteLine(operation(id) ? "Done." : "Task not found."); } void Show(IEnumerable<TodoItem> items) { var list = items.ToList(); if (list.Count == 0) { Console.WriteLine("Nothing here."); return; } foreach (var i in list) Console.WriteLine($"[{(i.IsDone ? "x" : " ")}] #{i.Id,-3} {i.Title,-30} {i.Priority,-6} {i.DueDate?.ToString("yyyy-MM-dd") ?? "-"}"); }

How It Works

PartResponsibility
TodoItemData
TodoStoreReading and writing the JSON file
TodoServiceRules: add, complete, delete, filter
Program.csTalking to the user
Why separate classes? Each class has one job. You can replace the JSON file with a database later by changing only TodoStore.

Challenges

  • Add an edit title option
  • Add search by text
  • Add a Tags list and filter by tag
  • Write xUnit tests for TodoService by making TodoStore an interface
  • Replace the menu with System.CommandLine

Conclusion

You built a layered console app using models, storage, services and a menu loop. This structure is the same one you will use in larger web projects.

Quick Summary: Model, Store, Service, UI. LINQ for filtering, JSON for persistence.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators