public ToDoItem CreateToDoItem(Guid listId, ToDoItemDTO item, string owner) { ToDoList toDoList = GetToDoList(listId, owner); if (toDoList == null) { throw new EntityNotFoundException(); } else if (toDoList.Owner != owner) { throw new UnauthorizedException(); } ToDoItem modelItem = item.ToEntity(toDoList); modelItem.Position = toDoList.Items.Count; toDoList.Items.Add(modelItem); _context.SaveChanges(); return(modelItem); }
public void UpdateToDoItem(Guid listId, ToDoItemDTO item, string owner) { ToDoList toDoList = GetToDoList(listId, owner); if (toDoList == null) { throw new EntityNotFoundException(); } else if (toDoList.Owner != owner) { throw new UnauthorizedException(); } ToDoItem oldItem = toDoList.Items.SingleOrDefault(i => i.Id.Equals(item.Id)); if (oldItem == null) { throw new EntityNotFoundException(); } oldItem.Update(item.ToEntity(toDoList)); _context.SaveChanges(); }