public ActionResult Create([Bind(Include = "DepositID,Date,Amount,Description,Comments")] Deposit deposit, Int32 BankAccountID)
        {
            //find selected account
            BankAccount SelectedAccount = db.Accounts.Find(BankAccountID);



            //associate with deposit
            deposit.Account = SelectedAccount;

            if (SelectedAccount.AccountType == AccountTypes.IRA)
            {
                int result = AccountUtitlities.IRA_Deposit(deposit);
                if (result == -1)
                {
                    return(View(deposit));
                }
            }

            //get balance
            Decimal Balance = SelectedAccount.Balance;

            Balance = Balance + deposit.Amount;
            SelectedAccount.Balance = Balance;
            if (ModelState.IsValid)
            {
                AccountUtitlities.GetDescription(deposit);
                db.Deposits.Add(deposit);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AllAccounts = GetAllAccounts(deposit);
            return(View(deposit));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "WithdrawID,Date,Amount,Description,Comments")] Withdraw withdraw, Int32 BankAccountID)
        {
            BankAccount SelectedAccount = db.Accounts.Find(BankAccountID);


            //associate with transaction
            withdraw.Account = SelectedAccount;

            Decimal Balance = SelectedAccount.Balance;

            Balance = Balance - withdraw.Amount;
            SelectedAccount.Balance = Balance;
            if (ModelState.IsValid)
            {
                AccountUtitlities.GetDescription(withdraw);
                db.Withdrawals.Add(withdraw);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.AllAccounts = GetAllAccounts(withdraw);
            return(View(withdraw));
        }