public async Task <IActionResult> UpdateDoNotDoItem(long id, DoNotDoItem doNotDoItem) { if (id != doNotDoItem.Id) { return(BadRequest()); } var newDoNotDoItem = await _context.DoNotDoItems.FindAsync(id); if (newDoNotDoItem == null) { return(NotFound()); } newDoNotDoItem.Name = doNotDoItem.Name; newDoNotDoItem.DidDo = doNotDoItem.DidDo; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!DoNotDoItemExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <TodoItemDTO> > CreateDoNotDoItem(DoNotDoItem doNotDoItem) { var newDoNotDoItem = new DoNotDoItem { DidDo = doNotDoItem.DidDo, Name = doNotDoItem.Name }; _context.DoNotDoItems.Add(newDoNotDoItem); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetDoNotDoItem), new { id = newDoNotDoItem.Id }, newDoNotDoItem)); }