public async Task <TransferResponse> Transferir(TransferRequest request)
        {
            try
            {
                TransferResponse response = new TransferResponse();

                var transferenciaDebitoEntity  = _mapper.Map <TransferenciaDebitoEntity>(request);
                var transferenciaCreditoEntity = _mapper.Map <TrasnferenciaCreditoEntity>(request);

                transferenciaDebitoEntity.Validate(transferenciaDebitoEntity);
                transferenciaCreditoEntity.Validate(transferenciaCreditoEntity);

                if (!(transferenciaDebitoEntity.Valid || transferenciaCreditoEntity.Valid))
                {
                    _notification.AddNotifications(transferenciaDebitoEntity.ValidationResult);
                    _notification.AddNotifications(transferenciaCreditoEntity.ValidationResult);
                    return(response);
                }

                response.Data.TransactionId = await _transferenciaService.Transferir(transferenciaDebitoEntity, transferenciaCreditoEntity);

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public async Task <ExampleCreateResponse> CreateAsync(ExampleCreateRequest request) => await ExecuteAsync(async() =>
 {
     var response = new ExampleCreateResponse();
     var obj      = ExampleDomain.Create(request.Age, request.Name);
     obj.Validate(obj, new ExampleValidator());
     if (!obj.Valid)
     {
         _notification.AddNotifications(obj.ValidationResult);
         return(response);
     }
     await _exampleRepository.InsertOrUpdateAsync(obj).ConfigureAwait(false);
     return(response);
 });
Exemplo n.º 3
0
        private async Task <AccountResponse> ExecutarTrasferencia(Guid trasnferenciaID, TransferenciaEntity transferenciaEntity)
        {
            _notification.ClearNotifications();
            var accountResponse = new AccountResponse();

            var account = await ValidarConta(transferenciaEntity.Conta);

            account.Validate(account);

            if (!account.Valid)
            {
                _notification.AddNotifications(account.ValidationResult);
                accountResponse.Success = false;
            }

            if (transferenciaEntity.TipoTransacao == Common.Enums.Transacao.ETipoTransacao.Debito)
            {
                if (account.Balance < transferenciaEntity.Valor)
                {
                    _notification.AddNotification("Conta", "Conta sem saldo para transferencia");
                    accountResponse.Success = false;
                }
            }

            if (!_notification.HasNotifications)
            {
                var request = new AccountRequest()
                {
                    AccountNumber = transferenciaEntity.Conta,
                    Type          = transferenciaEntity.TipoTransacao == Common.Enums.Transacao.ETipoTransacao.Debito ? Common.Enums.Transacao.AccountTransactionType.Debit : Common.Enums.Transacao.AccountTransactionType.Credit,
                    Value         = transferenciaEntity.Valor
                };

                accountResponse = await _accountHttpClient.InserirTrasactionAccount(request);
            }

            transferenciaEntity.AtribuirIdTransferencia(trasnferenciaID);
            await InserirTransferencia(transferenciaEntity);

            return(accountResponse);
        }