示例#1
0
        public static void ValidarCommand(AtualizarTaxaCommand request, AtualizarTaxaResponse response)
        {
            var validator = new AtualizarTaxaCommandValidator();

            var resultadoValidacao = validator.Validate(request);

            if (!resultadoValidacao.IsValid)
            {
                var invalidCommandArguments = Errors.General.InvalidCommandArguments();

                foreach (var erro in resultadoValidacao.Errors)
                {
                    invalidCommandArguments.AddErroDetail(Errors.General.InvalidArgument(erro.ErrorCode, erro.ErrorMessage));
                }

                response.AddError(invalidCommandArguments);
            }
        }
示例#2
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);
        }
示例#3
0
        public static Response ValidarCommand(AtualizarTaxaCommand request)
        {
            var validator = new AtualizarTaxaCommandValidator();

            var resultadoValidacao = validator.Validate(request);

            if (resultadoValidacao.IsValid)
            {
                return(Response.Ok());
            }

            var invalidCommandArguments = Errors.General.InvalidCommandArguments();

            for (int i = 0; i < resultadoValidacao.Errors.Count; i++)
            {
                var erro = resultadoValidacao.Errors[i];
                invalidCommandArguments.AddErroDetail(Errors.General.InvalidArgument(erro.ErrorCode, erro.ErrorMessage));
            }

            return(Response.Fail(invalidCommandArguments));
        }