public async ValueTask <ICommandResult> Handle(PagarContratoCommand command)
        {
            if (!command.Validate())
            {
                AddNotifications(command);
                return(new CommandResult(false, base.Notifications));
            }

            var entityContrato = await _contratoRepository.GetById(command.ContratoId).ConfigureAwait(true);

            if (entityContrato is null)
            {
                AddNotification("Contrato", "Contrato nao Encontrado.");
                return(new CommandResult(false, base.Notifications));
            }

            var dadosPagamento = new DadosPagamentos(command.Valor, command.Status, command.Bandeira, command.NumeroCartao, command.DataExpiracao, command.CVV, command.DataPagamento, entityContrato.Id);
            await _pagamentoRepository.Add(dadosPagamento).ConfigureAwait(true);

            var result = await _pagamentoRepository.SaveChanges().ConfigureAwait(true);

            if (!result)
            {
                AddNotification("Contrato", "Devolucao nao pode ser Registrada");
                return(new CommandResult(false, base.Notifications));
            }
            return(new CommandResult(true));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PatchPagamentoAsync(PagarContratoCommand command)
        {
            var result = await _commandPagar.Handle(command).ConfigureAwait(true) as CommandResult;

            if (result.Success)
            {
                return(Ok());
            }
            else
            {
                return(UnprocessableEntity());
            }
        }