public async Task <ActionResult <TodoItemDto> > UpdateTodoItem(long id, TodoItemUpdateDto todoItemUpdateDto) { if (!TryValidateModel(todoItemUpdateDto, nameof(TodoItemUpdateDto))) { return(BadRequest()); } var todoItem = await _todoContext.TodoItems.FindAsync(id); if (todoItem == null) { return(NotFound()); } _todoContext.Entry(todoItem).State = EntityState.Modified; todoItem.IsComplete = todoItemUpdateDto.IsComplete ?? false; todoItem.Name = todoItemUpdateDto.Name; if (todoItem.IsComplete == false) { todoItem.TimeCompleted = null; } else { todoItem.TimeCompleted = DateTime.UtcNow; } await _todoContext.SaveChangesAsync(); return(await GetTodoItem(id)); }
public ActionResult <TodoItem> UpdateTodoItem(int id, IFormCollection data) { var todoItemModelFromRepo = _repository.GetTodoItemById(id); if (todoItemModelFromRepo == null) { return(NotFound()); } var todoItemUpdateDto = new TodoItemUpdateDto(); todoItemUpdateDto.SetValues(data); _mapper.Map(todoItemUpdateDto, todoItemModelFromRepo); _repository.UpdateTodoItem(todoItemModelFromRepo); _repository.SaveChanges(); return(Ok(todoItemModelFromRepo)); }
public ActionResult UpdateTodoItem(int id, TodoItemUpdateDto todoItemUpdateDto) { // gets the object in the oficial model from database var todoItemModelFromRepo = _repository.GetTodoItemById(id); if (todoItemModelFromRepo == null) { return(NotFound()); } //merge where new -> replaces current _mapper.Map(todoItemUpdateDto, todoItemModelFromRepo); //calls update(but it does do anything since there is no implementation of the method update) _repository.UpdateTodoItem(todoItemModelFromRepo); //commits the object merged with the changes [todoItemModelFromRepo] _repository.SaveChanges(); return(NoContent()); }
public ActionResult UpdateTodoItem(int id, TodoItemUpdateDto todoItem) { throw new System.NotImplementedException(); }