public List <ToDoItemDTO> UpdateToDoItemPosition(Guid listId, Guid itemId, int position, string owner) { ToDoList toDoList = GetToDoList(listId, owner); if (toDoList == null) { throw new EntityNotFoundException(); } else if (toDoList.Owner != owner) { throw new UnauthorizedException(); } ToDoItem toDoItem = toDoList.Items.SingleOrDefault(i => i.Id.Equals(itemId)); if (toDoItem == null) { throw new EntityNotFoundException(); } int maxPosition = toDoList.Items.Count - 1; if (position > maxPosition || position < 0) { throw new InvalidPositionException(); } toDoItem.UpdatePosition(position); _context.SaveChanges(); return(GetToDoItems(listId, owner)); }