public async Task <ActionResult <IEnumerable <TodoItem> > > GetTodoItems() { using (var repo = new TodoDAO(_context)) { return(await repo.Get()); } }
public TodoController(TodoContext context) { _context = context; using (var repo = new TodoDAO(_context)) { repo.Initialize(); } }
public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item) { using (var repo = new TodoDAO(_context)) { await repo.Create(item); } return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item)); }
public async Task <IActionResult> PutTodoItem(long id, TodoItem item) { if (id != item.Id) { return(BadRequest()); } using (var repo = new TodoDAO(_context)) { await repo.Update(item); } return(NoContent()); }
public async Task <IActionResult> DeleteTodoItem(long id) { using (var repo = new TodoDAO(_context)) { var todoItem = await repo.Find(id); if (todoItem == null) { return(NotFound()); } await repo.Delete(todoItem); return(NoContent()); } }
public async Task <ActionResult <TodoItem> > GetTodoItem(long id) { TodoItem result = null; using (var repo = new TodoDAO(_context)) { result = await repo.Find(id); } if (result == null) { return(NotFound()); } else { return(result); } }