Пример #1
0
        public ActionResult Withdraw(CheckingAccount checkingAccount)
        {
            if (ModelState.IsValid)
            {
                CheckingTransactionsController c = new CheckingTransactionsController();
                CheckingTransaction            transaction;

                var withdrawAmount = checkingAccount.Balance;
                checkingAccount.Balance = (double)TempData["CheckingBalance"];
                if (withdrawAmount > checkingAccount.Balance)
                {
                    return(RedirectToAction("WithdrawDenied", new { id = checkingAccount.CustomerId }));
                }
                else
                {
                    checkingAccount.Balance -= withdrawAmount;
                    transaction              = c.CreateTransaction(checkingAccount.CustomerId, checkingAccount.Id, withdrawAmount, "Withdraw");
                    db.CheckingTransaction.Add(transaction);
                    db.Entry(checkingAccount).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = checkingAccount.CustomerId }));
                }
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", checkingAccount.CustomerId);
            return(RedirectToAction("Index", new { id = checkingAccount.CustomerId }));
        }
Пример #2
0
        public ActionResult Deposit(CheckingAccount checkingAccount)
        {
            if (ModelState.IsValid)
            {
                CheckingTransactionsController c = new CheckingTransactionsController();
                CheckingTransaction            transaction;
                double depositAmount = checkingAccount.Balance;
                checkingAccount.Balance += (double)TempData["AccountBalance"];
                transaction              = c.CreateTransaction(checkingAccount.CustomerId, checkingAccount.Id, depositAmount, "Deposit");
                db.CheckingTransaction.Add(transaction);

                db.Entry(checkingAccount).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = checkingAccount.CustomerId }));
            }
            ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", checkingAccount.CustomerId);
            return(View(checkingAccount.CustomerId));
        }