public IActionResult Put(long id, [FromBody] TodoItemDto todoItemDto) { try { var command = new ChangeTodoItemCommand(todoItemDto.Description, todoItemDto.IsCompleted); command.Id = id; command.Validate(); if (command.Invalid) { return(BadRequest(command)); } _todoItemCommandHandler.Handle(command); return(Ok(command)); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(BadRequest(ex)); } }
public void Handle(ChangeTodoItemCommand command) { var todoItem = _todoItemService.Read(x => x.Id == command.Id).FirstOrDefault(); if (todoItem == null) { throw new NotFoundException("Objeto não encontrado.", null); } if (command.Invalid) { return; } todoItem.ChangeInformations(command.Description, command.IsCompleted); _todoItemService.Update(todoItem); }