public CadastrarContaCorrenteResult Executar(CadastrarContaCorrenteRequest request) { if (_contaCorrenteRepositorio.Obter(request.Conta) != null) { _notificationContext.AddNotification(nameof(request.Conta), "Conta já cadastrada"); return(new CadastrarContaCorrenteResult()); } ContaCorrente conta = new ContaCorrente(Guid.NewGuid(), request.Agencia, request.Conta); if (conta.Invalid) { _notificationContext.AddNotifications(conta.Notifications); return(new CadastrarContaCorrenteResult()); } _contaCorrenteRepositorio.Salvar(conta); return(CadastrarContaCorrenteResult.FromDomain(conta)); }
public Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { if (_validators.Any()) { var context = new ValidationContext <object>(request); var validationResults = _validators .Select(v => v.Validate(context)) .ToList(); if (validationResults != null && validationResults.Any()) { validationResults .ForEach(validationResult => _notificationContext.AddNotifications(validationResult)); throw new ValidationException(ApplicationMessages.RequestValidationPipeline_Invalid_Request); } } return(next()); }
private async Task <SegmentDto> OnExecutingAsync(long segmentId, decimal exchangeRate, CancellationToken cancellationToken) { try { var segment = await _mediator.Send(new GetSegmentByIdQuery(segmentId), cancellationToken); if (segment is null) { _notificationContext.AddNotification(ApplicationMessages.UpdateSegmentExchangeRateUseCase_Segmento_Not_Found); return(null); } segment.SetExchangeRate(exchangeRate); if (!segment.Valid) { _notificationContext.AddNotifications(segment.ValidationResult); return(null); } await _mediator.Send(new UpdateSegmentCommand(segment), cancellationToken); if (_notificationContext.HasNotifications) { return(null); } return(new SegmentDto { Id = segment.Id, Name = segment.Name, ExchangeRate = segment.ExchangeRate }); } catch (Exception ex) { _notificationContext.AddNotification(ex); } return(null); }
protected Unit Fail(string[] messages) { _notificationContext.AddNotifications(messages); return(Unit.Value); }
public void AddNotifications(ICollection <Notification> notifications) => notificationContext.AddNotifications(notifications);