Untitled
unknown
plain_text
a month ago
860 B
2
Indexable
Never
using System; using System.Collections.Generic; using System.Linq; public class TodoRepository { private List<Todo> todos = new List<Todo>(); public List<Todo> GetAll() => todos; public Todo Get(int id) => todos.FirstOrDefault(t => t.Id == id); public void Add(Todo todo) { todo.Id = todos.Count + 1; // Assign a new ID todos.Add(todo); } public void Update(Todo todo) { var existingTodo = todos.FirstOrDefault(t => t.Id == todo.Id); if (existingTodo != null) { existingTodo.Title = todo.Title; existingTodo.IsComplete = todo.IsComplete; } } public void Delete(int id) { var existingTodo = todos.FirstOrDefault(t => t.Id == id); if (existingTodo != null) { todos.Remove(existingTodo); } } }