Ejemplo n.º 1
0
        public async Task <TransportEntity> InternalTransaction(AddCheckingAccountTransactionCommand Command)
        {
            try
            {
                if (Command.CreditCheckingAccount == Command.DebitCheckingAccount)
                {
                    ObjReturn.Sucess = false;
                    ObjReturn.Messages.Add("Conta de Debito e Credito iguais");
                    return(ObjReturn);
                }

                if (Command.Value <= 0)
                {
                    ObjReturn.Sucess = false;
                    ObjReturn.Messages.Add("Valor deve ser maior que 0");
                    return(ObjReturn);
                }

                Aggregates.CheckingAccount DebitCheckingAccount = await ValidatedCheckingAccount(Command.DebitCheckingAccount);

                if (DebitCheckingAccount.Active.Equals(false))
                {
                    ObjReturn.Sucess = false;
                    ObjReturn.Messages.Add("Conta de Debito invalidas");
                    return(ObjReturn);
                }

                Aggregates.CheckingAccount CreditCheckingAccount = await ValidatedCheckingAccount(Command.CreditCheckingAccount);

                if (CreditCheckingAccount.Active.Equals(false))
                {
                    ObjReturn.Sucess = false;
                    ObjReturn.Messages.Add("Conta de Credito invalidas");
                    return(ObjReturn);
                }

                if (Command.Value > GetBalance(Command.DebitCheckingAccount))
                {
                    ObjReturn.Sucess = false;
                    ObjReturn.Messages.Add("Saldo Insuficiente");
                    return(ObjReturn);
                }

                Guid TracedID = Guid.NewGuid();

                IEnumerable <CheckingAccountTransaction> TransactionList = new List <CheckingAccountTransaction>()
                {
                    new CheckingAccountTransaction()
                    {
                        ID              = Guid.NewGuid(),
                        TracedID        = TracedID,
                        CheckingAccount = DebitCheckingAccount,
                        Value           = (Command.Value * -1),
                        CheckingAccountTransactionStatus = await checkingAccountTransactionStatusRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionStatusEnum.Authorized), true),
                        CheckingAccountTransactionType   = await checkingAccountTransactionTypeRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionTypeEnum.InternalTransfer), true),
                        CurrencyType = await currencyRepository.GetAsync(w => w.Code.Equals((int)CurrencyEnum.BRL), true)
                    },
                    new CheckingAccountTransaction()
                    {
                        ID              = Guid.NewGuid(),
                        TracedID        = TracedID,
                        CheckingAccount = CreditCheckingAccount,
                        Value           = Command.Value,
                        CheckingAccountTransactionStatus = await checkingAccountTransactionStatusRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionStatusEnum.Authorized), true),
                        CheckingAccountTransactionType   = await checkingAccountTransactionTypeRepository.GetAsync(w => w.Code.Equals((int)CheckingAccountTransactionTypeEnum.InternalTransfer), true),
                        CurrencyType = await currencyRepository.GetAsync(w => w.Code.Equals((int)CurrencyEnum.BRL), true)
                    }
                };


                await checkingAccountTransactionRepository.AddRangeAsync(TransactionList);

                ObjReturn.Sucess = true;
                ObjReturn.Data   = true;
                return(ObjReturn);
            }
            catch (Exception ex)
            {
                ObjReturn.Sucess = false;
                ObjReturn.Messages.Add(ex.Message);
                return(ObjReturn);
            }
        }
Ejemplo n.º 2
0
 public async Task <Aggregates.CheckingAccount> AddCheckingAccount(Aggregates.CheckingAccount CheckingAccount)
 {
     return(await checkingAccountRepository.AddAsync(CheckingAccount));
 }