public async Task <IActionResult> PutTodo(Guid id, TodoRequest todo) { if (id == Guid.Empty) { return(BadRequest()); } //MAP var todoToEdit = todo.Adapt <Todo>(); todoToEdit.Id = id; _context.Entry(todoToEdit).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Todo> > PostTodo(TodoRequest todo) { //VALIDATE //MAP var newTodo = todo.Adapt <Todo>(); _context.Todos.Add(newTodo); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodo", new { id = newTodo.Id }, newTodo)); }