public ActionResult BillSchedule(ATMBillSchedule_ViewModel models) { int sessionUserID = WebSecurity.GetUserId(User.Identity.Name); Bank bank = new Bank(); if (ModelState.IsValid) { HttpContext.Session["accountNumber"] = null; return View(bank.billSchedulePost(sessionUserID, models)); } else { return BillSchedule(); } }
/*PayBillScheduleGet *This creates the viewmodel to displays the the grid of schdueled jobs for the user */ public ATMBillSchedule_ViewModel billSchedule(int sessionID) { NWBAEntities db = new NWBAEntities(); var customerQuery = Repo.GetCustomerSingle(sessionID); var AccountListQuery = Repo.GetCustomerAccountQueryable(sessionID); IEnumerable<SelectListItem> account = 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() }); var newModel = new ATMBillSchedule_ViewModel { CustomerName = customerQuery.CustomerName, accountList = account, scheduleBillList = new List<BillingList>() }; return newModel; }
/*PayBillSchedulePost *User submits the view to view the pending billpay jobs *This post also retrieves the current jobs for the particular account and creates a list for the view to display */ public ATMBillSchedule_ViewModel billSchedulePost(int sessionID, ATMBillSchedule_ViewModel models) { NWBAEntities db = new NWBAEntities(); int accountID = models.AccountNumber; if (accountID != 0) { var accountQuery = Repo.GetAccount(accountID); var customerQuery = Repo.GetCustomerAccountQueryable(sessionID); var singleCustomerQuery = Repo.GetCustomerSingle(sessionID); IEnumerable<SelectListItem> accounts = customerQuery.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() }); //This fetches a list of current billpay jobs scheduled ######### var currentJobsList = Repo.GetCurrentBillPayJobs(); //Get all Billpay records in the system that are currently being schedueld and for the particular account var billList = (from a in db.BillPays where a.AccountNumber.Equals(accountID) && currentJobsList.Contains(a.BillPayID) select a); var payeeList = Repo.GetAllPayeeQueryable(); //If the account has at least 1 schecduled billpay job //enter this if, Else display empty record string if (billList.Count() > 0) { //select [WDT].[dbo].[Payee].PayeeName, [WDT].[dbo].[BillPay].PayeeID, // [WDT].[dbo].[BillPay].Amount, [WDT].[dbo].[BillPay].ScheduleDate, [WDT].[dbo].[BillPay].Period //from [WDT].[dbo].[Payee] //join [WDT].[dbo].[BillPay] //on [WDT].[dbo].[Payee].PayeeID=[WDT].[dbo].[BillPay].PayeeID //Creates a list of billing list objects which is needed by the grid to display the current scheduled jobs for the account List<BillingList> BillPayGridList = new List<BillingList>(); // Contains an annomous object with properties from billpay and payee //A list of current billpay jobs with information from payee table var CustomScheduledList = (from x in db.BillPays join y in db.Payees on x.PayeeID equals y.PayeeID where x.AccountNumber.Equals(accountID) && currentJobsList.Contains(x.BillPayID) select new { x.BillPayID, y.PayeeName, x.Amount, x.ScheduleDate, x.Period }); foreach (var z in CustomScheduledList) { string scheduleDateFormat = z.ScheduleDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); BillingList bl = new BillingList(); bl.BillPayID = z.BillPayID; bl.PayeeName = z.PayeeName; bl.Amount = (double)z.Amount; bl.ScheduleDate = scheduleDateFormat; bl.Period = z.Period; BillPayGridList.Add(bl); } models.CustomerName = singleCustomerQuery.CustomerName; models.AccountNumber = accountID; models.accountList = accounts; models.scheduleBillList = BillPayGridList; } else { //This part basically creates a viewmodel that tells the user //they dont have any schduled bill pay jobs List<BillingList> bList = new List<BillingList>(); models.CustomerName = singleCustomerQuery.CustomerName; models.AccountNumber = accountID; models.accountList = accounts; models.scheduleBillList = bList; models.Message = "Empty Record"; } } else { billSchedule(sessionID); } return models; }