public async Task <ICommandResult <Unit> > Handle(DeleteTodoListItemCommand request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request, cancellationToken); if (!validationResult.IsValid) { return(CommandResult <Unit> .Failure(validationResult.Errors)); } var todoListItem = await _todoListItemsRepository .GetTodoListItemsByIdAsync(request.TodoListItemId, cancellationToken); _todoListItemsRepository.Remove(todoListItem); await _todoListItemsRepository.SaveChangesAsync(cancellationToken); return(CommandResult <Unit> .Success(Unit.Value, "The to-do item was deleted successfully")); }
public async Task <ICommandResult <Guid> > Handle(AddTodoListItemCommand request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request, cancellationToken); if (!validationResult.IsValid) { return(CommandResult <Guid> .Failure(validationResult.Errors)); } var todoListItem = TodoListItem.CreateNew(request.Name, request.Description, request.DueDate); _todoListItemsRepository.Insert(todoListItem); await _todoListItemsRepository.SaveChangesAsync(cancellationToken); return(CommandResult <Guid> .Success(todoListItem.TodoListItemId, "The to-do item was added successfully")); }