Exemplo n.º 1
0
        public void AddorReplaceUser(TransferenciaEntity transferencia)
        {
            table.CreateIfNotExistsAsync();
            TableOperation insertOp = TableOperation.InsertOrReplace(transferencia);

            table.ExecuteAsync(insertOp);
        }
Exemplo n.º 2
0
        public async Task InserirTransferencia(TransferenciaEntity entity) => await _dapper.ExecuteQueryAsync(async connection =>
        {
            //var chaveTransancao = entity.GerarIdTransferencia();

            var query = @"
                            INSERT INTO [dbo].[TRANSFERENCIA]
                                       ([CONTA]
                                       ,[VALOR_TRASFERENCIA]
                                       ,[ID_TRANSACAO]
                                       ,[STATUS]
                                       ,[TIPO_TRANSACAO]
                                       ,[DATA_TRANSACAO])
                                 VALUES
                                       (@Conta,
										@Valor,
										@IdTransferencia,
										@StatusTrasferencia,
										@TipoTransacao,
										@DataTransferencia)
							"                            ;

            return(await connection.QueryFirstOrDefaultAsync(sql: query, param: new
            {
                entity.Conta,
                entity.Valor,
                @IdTransferencia = entity.IdTransferencia,
                entity.StatusTrasferencia,
                entity.TipoTransacao,
                entity.DataTransferencia
            }));
        });
Exemplo n.º 3
0
        private async Task <AccountResponse> ExecutarTrasferenciaEstorno(TransferenciaEntity transferenciaEntity)
        {
            _notification.ClearNotifications();
            var accountResponse = new AccountResponse();

            transferenciaEntity.AtribuirTipoTransacao(Common.Enums.Transacao.ETipoTransacao.Estorno);

            var request = new AccountRequest()
            {
                AccountNumber = transferenciaEntity.Conta,
                Type          = Common.Enums.Transacao.AccountTransactionType.Credit,
                Value         = transferenciaEntity.Valor
            };

            accountResponse = await _accountHttpClient.InserirTrasactionAccount(request);

            if (!accountResponse.Success)
            {
                _notification.AddNotification("Conta", "Problema a fazer o estorno.");
            }


            await InserirTransferencia(transferenciaEntity);

            return(accountResponse);
        }
Exemplo n.º 4
0
        public async Task <bool> ContasExistentes(TransferenciaEntity transferenciaEntity)
        {
            var accounts = await _accountHttpClient.ObterAccounts();

            if (accounts.BalanceAdjustmentResponses.Select(x => x.AccountNumber == transferenciaEntity.ContaOrigem && x.AccountNumber == transferenciaEntity.ContaDestino).Count() == 2)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public async Task <TransferenciaEntity> RetrieveTransferenciaAsync(string id, string name)
        {
            bool b = table.ExistsAsync().Result;

            TableOperation retOp = TableOperation.Retrieve <TransferenciaEntity>(id, name);

            TableResult tr = await table.ExecuteAsync(retOp);

            TransferenciaEntity transferencia = ((TransferenciaEntity)tr.Result);

            return(transferencia);
        }
Exemplo n.º 6
0
        public async Task InserirTransferencia(TransferenciaEntity entity)
        {
            entity.ExisteErro(_notification.HasNotifications);

            await _transferenciaRepository.InserirTransferencia(entity);

            if (_notification.HasNotifications)
            {
                entity.TrasnferenciaErroEntity.AtribuirDescricaoErro(_notification.Notifications.Select(error => error).FirstOrDefault().Message);
                await _transferenciaRepository.InserirTransferenciaErro(entity.TrasnferenciaErroEntity);
            }
        }
Exemplo n.º 7
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);
        }