Пример #1
0
        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();
        }
Пример #2
0
        public async Task GetAllAsync(TodoDbContext db, HttpContext context)
        {
            var todos = await db.TodoItems.ToListAsync();

            await context.Response.WriteJsonAsync(todos, _options);
        }