Exemple #1
0
        /// <summary/>
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                _uow.Rollback();
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _mediator.Notify(new DomainNotification("Commit", Mensagens.ErroCommit));
            return(false);
        }
Exemple #2
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken,
                                             RequestHandlerDelegate <TResponse> next)
        {
            var failures = _validators
                           .Select(v => v.Validate(request))
                           .SelectMany(result => result.Errors)
                           .Where(error => error != null)
                           .ToList();

            if (failures.Any())
            {
                foreach (var validationFailure in failures)
                {
                    await _bus.Notify(new DomainNotification(request.MessageType, validationFailure.ErrorMessage));
                }
                return((TResponse)CommandResponse.Fail);
            }

            var response = await next();

            return(response);
        }