示例#1
0
        public IActionResult Index(Transaction transaction)
        {
            var bankController = new BankController();
            var bank           = _repository.GetBank();

            var accFrom = _repository.GetAccount(transaction.AccountFrom);
            var accTo   = _repository.GetAccount(transaction.AccountTo);

            if (!(transaction.Amount > 0))
            {
                ViewBag.Error = "Please enter valid amount";
                return(View(transaction));
            }

            if (accFrom == null || accTo == null)
            {
                ViewBag.Error = "Account cannot be found";
                return(View(transaction));
            }

            if (!bankController.Transfer(accFrom, accTo, transaction.Amount))
            {
                ViewBag.Error = "Not enough funds";
                return(View(transaction));
            }

            return(View("Success", new Account[] { accFrom, accTo }));
        }
示例#2
0
        public IActionResult Transaction(string submitButton, decimal value, int account)
        {
            var bankController = new BankController();

            var requestedAccount = _repository.GetAccount(account);

            var bank = _repository.GetBank();

            if (requestedAccount != null)
            {
                switch (submitButton)
                {
                case "Deposit":
                    var updateAcc = bankController.Deposit(requestedAccount, value);
                    bank.Customers.SelectMany(x => x.Account.Where(y => y.AccountNumber == account)).FirstOrDefault().Moneyz = updateAcc.Moneyz;
                    _repository.SaveBank(bank);
                    return(View(updateAcc));

                case "Withdraw":
                    var result = bankController.Withdraw(requestedAccount, value);
                    if (result != null)
                    {
                        bank.Customers.SelectMany(x => x.Account.Where(y => y.AccountNumber == account)).FirstOrDefault().Moneyz = result.Moneyz;
                        _repository.SaveBank(bank);
                        return(View(result));
                    }
                    return(RedirectToAction("DepoWith", new { error = "Not enough balance to withdraw." }));

                default:

                    return(RedirectToAction("DepoWith"));
                }
            }
            else if (requestedAccount == null)
            {
                return(RedirectToAction("DepoWith", new { error = "No account with that number." }));
            }

            return(RedirectToAction("DepoWith"));
        }