public ActionResult StatementView(Statement_ViewModel models) { int SessionUserID = WebSecurity.GetUserId(User.Identity.Name); Bank bank = new Bank(); if (ModelState.IsValid) { HttpContext.Session["accountNumber"] = models.AccountNumber; return View(bank.postStatement(SessionUserID, models)); } else { HttpContext.Session["accountNumber"] = null; return StatementView(); } }
//StatementPost public Statement_ViewModel postStatement(int sessionID, Statement_ViewModel models) { using (NWBAEntities db = new NWBAEntities()) { int accountID = models.AccountNumber; if (accountID != 0) { var accountQuery = Repo.GetAccount(accountID); var customerAccountsQuery = Repo.GetCustomerAccountQueryable(sessionID); IEnumerable<SelectListItem> accounts = customerAccountsQuery.OrderBy(c => c.AccountNumber).ToList(). Select(c => new SelectListItem { Value = Convert.ToString(c.AccountNumber), Text = (c.AccountType.Equals("S")) ? "Saving " + c.AccountNumber.ToString() : "Checkings " + " " + c.AccountNumber.ToString() }); decimal balance = 0; decimal minSbalance = 0.20M; decimal minCbalance = 200.20M; decimal transactionFee = 0.20M; decimal balanceThreshold; Boolean check = false; if (accountQuery.AccountType.Equals("S")) { if (accountQuery.Balance >= minSbalance) { balance = accountQuery.Balance - transactionFee; check = true; } else { balance = accountQuery.Balance; } } else if (accountQuery.AccountType.Equals("C")) { if (accountQuery.Balance >= minCbalance) { balance = accountQuery.Balance - transactionFee; check = true; } else { balance = accountQuery.Balance; } } if (accountQuery.AccountType.Equals("S")) { balanceThreshold = SAVINGS_MINIMAL_BALANCE; } else { balanceThreshold = CHECKING_MINIMAL_BALANCE; } if (balance >= balanceThreshold && check) { DateTime date = System.DateTime.Now; Account updateAccount = db.Accounts.First(u => u.AccountNumber.Equals(accountID)); updateAccount.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance)); updateAccount.ModifyDate = date; Repo.UpdateExistingAccount(updateAccount); Transaction serviceTransaction = new Transaction { TransactionType = "S", AccountNumber = accountID, Amount = Convert.ToDecimal(string.Format("{0:0.00}", transactionFee)), Comment = "View Statement Charge", ModifyDate = date }; Repo.AddTransaction(serviceTransaction); models.retrieveMessage = "Transaction History Retrieved SUCCESSFULLY"; var sList = (from a in db.Transactions where a.AccountNumber.Equals(accountID) select a); models.AccountNumber = accountID; models.tranList = sList.ToList(); models.accountList = accounts; models.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance)); } else { models.retrieveMessage = "Transaction History Was Unable To Retrieve Due To INSUFFICIENT Amount"; var aList = (from a in db.Transactions where a.AccountNumber.Equals(0) select a); models.AccountNumber = accountID; models.accountList = accounts; models.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance)); models.tranList = aList.ToList(); } } else { return getStatement(sessionID); } return models; } }
//StatementGet public Statement_ViewModel getStatement(int sessionID) { NWBAEntities db = new NWBAEntities(); var AccountListQuery = Repo.GetCustomerAccountQueryable(sessionID); IEnumerable<SelectListItem> accounts = AccountListQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem { Value = Convert.ToString(a.AccountNumber), Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() : "Checkings - " + a.AccountNumber.ToString() }); if (HttpContext.Current.Session["accountNumber"] != null) { int accountNumber = (int)HttpContext.Current.Session["accountNumber"]; var transList = (from a in db.Transactions where a.AccountNumber.Equals(accountNumber) select a); var accountQuery = (from x in db.Accounts where x.CustomerID.Equals(sessionID) && x.AccountNumber.Equals(accountNumber) select x).Single(); var model = new Statement_ViewModel() { accountList = accounts, tranList = transList.ToList(), Balance = Convert.ToDecimal(string.Format("{0:0.00}", accountQuery.Balance)) }; return model; } else { var transList = (from a in db.Transactions where a.AccountNumber.Equals(0) select a); var model = new Statement_ViewModel() { accountList = accounts, tranList = transList.ToList(), }; return model; } }