Exemplo n.º 1
0
        public ActionResult TransferMoney(TransferMoneyViewModel viewModel)
        {
            var userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                return(View("TransferMoney", viewModel));
            }

            var transactions    = new List <Transaction>();
            var transactionType = unitOfWork.TransactionTypes.GetTransactionType(viewModel.TransactionCategory);
            var debitAccount    = unitOfWork.BankAccounts.GetJustBankAccount(viewModel.DebitAccNo);
            var creditAccNo     = viewModel.CreditAccNo ?? viewModel.CreditAccIban.Substring(10);
            var creditAccount   = unitOfWork.BankAccounts.GetJustBankAccount(creditAccNo);

            if (creditAccount == null)
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                viewModel.ErrorMessage     = "Credit Bank Account could not be found.";
                return(View("TransferMoney", viewModel));
            }

            if (!debitAccount.InitiateTransaction(creditAccount, viewModel.Amount.Value, transactionType, null, out transactions))
            {
                viewModel.CustomerBankAccs = unitOfWork.BankAccounts.GetCheckingAndSavingsBankAccs(userId);
                viewModel.ErrorMessage     = "Could not complete transaction.";
                return(View("TransferMoney", viewModel));
            }

            foreach (var transaction in transactions)
            {
                unitOfWork.Transactions.AddTransaction(transaction);
            }
            unitOfWork.Complete();

            var transHub = new
            {
                DebitAccountNo  = debitAccount.AccountNumber,
                DebitBalance    = debitAccount.Balance,
                CreditAccountNo = creditAccount.AccountNumber,
                CreditBalance   = creditAccount.Balance,
                DebitAmount     = transactions[0].DebitAmount,
                Time            = transactions[0].ValueDateTime.ToLongTimeString(),
                Date            = transactions[0].ValueDateTime.ToLongDateString()
            };

            SignalHub.GetTransactions(transHub);
            return(RedirectToAction("Index", new { AccountNumber = debitAccount.AccountNumber }));
        }
Exemplo n.º 2
0
        public IHttpActionResult MakePayment(TransactionInfoDto transactionDto)
        {
            var transactions    = new List <Transaction>();
            var userId          = User.Identity.GetUserId();
            var transactionType = unitOfWork.TransactionTypes.GetTransactionType(transactionDto.Category);
            var debitAccount    = unitOfWork.BankAccounts.GetJustBankAccount(transactionDto.DebitAccNo);
            var creditAccount   = unitOfWork.BankAccounts.GetJustBankAccount(transactionDto.CreditAccNo);
            var tsmBankAcc      = unitOfWork.BankAccounts.GetTsmBankAcc();

            if (creditAccount == null || debitAccount == null)
            {
                return(NotFound());
            }

            if (!debitAccount.InitiateTransaction(creditAccount, transactionDto.Amount, transactionType, tsmBankAcc, out transactions))
            {
                return(BadRequest("Transaction could not be completed."));
            }

            foreach (var transaction in transactions)
            {
                unitOfWork.Transactions.AddTransaction(transaction);
            }
            unitOfWork.Complete();

            var transHub = new
            {
                DebitAccountNo  = debitAccount.AccountNumber,
                DebitBalance    = debitAccount.Balance,
                CreditAccountNo = creditAccount.AccountNumber,
                CreditBalance   = creditAccount.Balance,
                DebitAmount     = transactions[0].DebitAmount,
                Time            = transactions[0].ValueDateTime.ToLongTimeString(),
                Date            = transactions[0].ValueDateTime.ToLongDateString()
            };

            SignalHub.GetTransactions(transHub);
            return(Ok());
        }