public async Task <ResultOf <TResponse> > Handle(TRequest request, CancellationToken cancellationToken) { var validationFailMessages = _validators.Select(i => i.Validate(request)) .SelectMany(i => i.Errors) .Select(i => i.ErrorMessage) .ToArray(); if (validationFailMessages.Any()) { var errors = string.Join("\n", validationFailMessages); return(ResultOf <TResponse> .BadRequest(errors)); } var result = await ProcessActionAsync(request, cancellationToken) .ConfigureAwait(false); if (_fails?.Any() ?? false) { var errors = string.Join("\n", _fails); return(ResultOf <TResponse> .BadRequest(errors)); } await _unitOfWork.CommitAsync().ConfigureAwait(false); // TODO Remove await, because do not need wait call end await PublishResultAsync(request, result); return(ResultOf <TResponse> .Ok(result)); }
public async Task <ResultOf <TResponse> > Handle(TRequest request, CancellationToken cancellationToken) { var validationFails = _validators.Select(i => i.Validate(request)) .Where(i => !i.IsValid) .SelectMany(i => i.Errors) .Select(i => i.ErrorMessage) .ToArray(); if (validationFails.Any()) { var errorMessage = string.Join("\n", validationFails); return(ResultOf <TResponse> .BadRequest(errorMessage)); } var queryResult = await ProcessQueryAsync(request, cancellationToken) .ConfigureAwait(false); return(ResultOf <TResponse> .Ok(queryResult)); }