public ActionResult Deposit(BusinessAccount businessAccount) { if (ModelState.IsValid) { BusinessTransactionsController c = new BusinessTransactionsController(); BusinessTransaction transaction; double depositAmount = businessAccount.Balance; businessAccount.Balance = (double)TempData["AccountBalance"]; businessAccount.Balance += depositAmount; db.Entry(businessAccount).State = EntityState.Modified; transaction = c.CreateTransaction(businessAccount.CustomerId, businessAccount.Id, depositAmount, "Deposit"); db.BusinessTransactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index", new { id = businessAccount.CustomerId })); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", businessAccount.CustomerId); return(View(businessAccount.CustomerId)); }
public ActionResult Withdraw(BusinessAccount businessAccount) { if (ModelState.IsValid) { BusinessTransactionsController c = new BusinessTransactionsController(); BusinessTransaction transaction; double withDrawAmount = businessAccount.Balance; businessAccount.Balance = (double)TempData["AccountBalance"]; double negativeAmount; if (businessAccount.Balance - withDrawAmount < -100) { //ViewBag.WithdrawDenied = "You have attempted to withdraw over your limit"; return(RedirectToAction("WithdrawDenied", new { id = businessAccount.CustomerId })); } else if (businessAccount.Balance - withDrawAmount < 0) { negativeAmount = businessAccount.Balance - withDrawAmount; negativeAmount += negativeAmount * BusinessAccount.OverdraftFee; businessAccount.Balance = negativeAmount; db.Entry(businessAccount).State = EntityState.Modified; transaction = c.CreateTransaction(businessAccount.CustomerId, businessAccount.Id, -withDrawAmount, "Withdraw"); db.BusinessTransactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index", new { id = businessAccount.CustomerId })); } else { businessAccount.Balance -= withDrawAmount; db.Entry(businessAccount).State = EntityState.Modified; transaction = c.CreateTransaction(businessAccount.CustomerId, businessAccount.Id, withDrawAmount, "Withdraw"); db.BusinessTransactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index", new { id = businessAccount.CustomerId })); } } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", businessAccount.CustomerId); return(View(businessAccount.CustomerId)); }