Пример #1
0
        public async Task <AtualizarTaxaResponse> Handle(AtualizarTaxaCommand request, CancellationToken cancellationToken)
        {
            var response = (AtualizarTaxaResponse)request.Response;

            AtualizarTaxaCommandValidator.ValidarCommand(request, response);
            if (response.IsFailure)
            {
                return(response);
            }

            await ObterTaxaPorId(request, response);

            if (response.IsFailure)
            {
                return(response);
            }

            CriarNovoValorTaxa(request, response);
            if (response.IsFailure)
            {
                return(response);
            }

            var atualizarTaxaResultado = TaxaCobranca.AtualizarTaxa(ValorTaxaCobranca);

            if (atualizarTaxaResultado.IsFailure)
            {
                response.AddError(Errors.General
                                  .InvalidCommandArguments()
                                  .AddErroDetail(Errors.AtualizarTaxaErros.ValorTaxaSemAlteracao(TaxaCobranca.ValorTaxa.Valor, request.NovaTaxa)));
                return(response);
            }

            await AtualizarTaxaCobranca(request, response);

            if (response.IsFailure)
            {
                return(response);
            }

            await Mediator.DispatchDomainEvents(TaxaCobranca);

            return(response);
        }