public async Task DeleteAsync(TodoDbContext db, HttpContext context) { if (!context.Request.RouteValues.TryGet("id", out int id)) { context.Response.StatusCode = 400; return; } var todo = await db.TodoItems.FindAsync(id); if (todo == null) { context.Response.StatusCode = 404; return; } db.TodoItems.Remove(todo); await db.SaveChangesAsync(); }
public async Task GetAllAsync(TodoDbContext db, HttpContext context) { var todos = await db.TodoItems.ToListAsync(); await context.Response.WriteJsonAsync(todos, _options); }