public async Task <ToDoItemViewModel> Handle(GetToDoItemQuery request, CancellationToken cancellationToken) { var toDoItem = await ToDoItemRepository.Get(request.Id); if (toDoItem == null) { throw new NotFoundException(request.Id, typeof(ToDoItem)); } return(new ToDoItemViewModel(toDoItem)); }
public async Task <bool> Handle(DeleteToDoItemCommand request, CancellationToken cancellationToken) { var toDoItem = await ToDoItemRepository.Get(request.Id); if (toDoItem == null) { throw new NotFoundException(request.Id, typeof(ToDoItem)); } await ToDoItemRepository.Delete(request.Id); return(true); }
public async Task <ToDoItemViewModel> Handle(UpdateToDoItemStatusCommand request, CancellationToken cancellationToken) { var toDoItem = await ToDoItemRepository.Get(request.Id); if (toDoItem == null) { throw new NotFoundException(request.Id, typeof(ToDoItem)); } toDoItem.IsComplete = request.IsComplete; var updateResponse = await ToDoItemRepository.Update(toDoItem); var viewModel = new ToDoItemViewModel(updateResponse); return(viewModel); }