public async Task <ActionResult <TodoEntryView> > CreateListEntry( [FromRoute] Guid id, [FromBody] ListEntryCreate entry) { var list = await db.Lists.FindAsync(id); if (list == null || list.Owner.Id != AuthorizedUser.Id) { return(NotFound()); } if (string.IsNullOrEmpty(entry.Content)) { return(BadRequest("content value can not be null or empty")); } var createdEntry = new TodoEntry() { Content = entry.Content, Checked = entry.Checked ?? false, ContainedIn = list, }; db.Add(createdEntry); await db.SaveChangesAsync(); return(Created( $"/api/lists/{list.Id}/entries/{createdEntry.Id}", new TodoEntryView(createdEntry))); }
public async Task <ActionResult <TodoEntryView> > UpdateListEntry( [FromRoute] Guid id, [FromRoute] Guid entryId, [FromBody] ListEntryCreate updatedEntry) { var entry = await GetListEntryChecked(id, entryId); if (entry == null) { return(NotFound()); } entry.Content = updatedEntry.Content ?? entry.Content; entry.Checked = updatedEntry.Checked ?? entry.Checked; db.Update(entry); await db.SaveChangesAsync(); return(Ok(new TodoEntryView(entry))); }