// GET: Customers public IActionResult Index() { // Check if customer is registered. string guid = GetUserGuID(); if (_repo.IsCustomerPresent(guid)) { // Display Main Account page. try { Customer currentCustomer = _repo.GetCustomer(guid); CustomerAccountsVM customerAccounts = _repo.GetCustomerAccounts(currentCustomer.ID); ViewData["CanMove"] = _repo.CanTransferBalance(currentCustomer.ID); ViewData["State"] = _repo.GetStates().FirstOrDefault(s => s.ID == currentCustomer.StateID).Name; ViewData["Account Types"] = _repo.GetAllAccountTypes(); return(View(customerAccounts)); } catch (Exception WTF) { Console.WriteLine(WTF); throw; } } else { // Redirect to create customer information page. return(RedirectToAction(nameof(Create))); } }
public virtual CustomerAccountsVM GetCustomerAccounts(int customerID, Utility.AccountType accountType) { CustomerAccountsVM result = new CustomerAccountsVM(); try { int accountTypeID = GetAccountTypeID(accountType); result.Customer = myContext.Customers.Where(c => c.ID == customerID).FirstOrDefault(); result.Accounts = myContext.Accounts. Where(a => a.CustomerID == customerID && a.AccountTypeID == accountTypeID && a.IsOpen && a.IsActive).ToList(); // Define each account type name. List <AccountType> allAccountTypes = GetAllAccountTypes(); // Check all accounts for type and deposit/withdrawability. result.AccountType = new List <string>(); result.isDepositable = new System.Collections.BitArray(result.Accounts.Count); result.isWithdrawable = new System.Collections.BitArray(result.Accounts.Count); result.isLoanPayable = new System.Collections.BitArray(result.Accounts.Count); int index = 0; foreach (var item in result.Accounts) { // Set account type name. result.AccountType.Add(allAccountTypes[item.AccountTypeID].Name); // Set flag for deposit account. result.isDepositable.Set(index, IsAccountDepositable(item)); // Set flag for withdraw account. result.isWithdrawable.Set(index, IsAccountWithdrawable(item)); // Set flag for loan payment account. result.isLoanPayable.Set(index, IsLoanAccount(item.AccountTypeID) && item.AccountBalance > 0.0); ++index; } } catch (Exception WTF) { Console.WriteLine(WTF); throw; } finally { } return(result); }
public CustomerAccountsVM GetCustomerAccounts(int customerID) { CustomerAccountsVM result = null; var customerQuery = Customers.Where(c => c.ID == customerID); var accountQuery = Accounts.Where(a => a.CustomerID == customerID); if (customerQuery.Count() > 0) { if (accountQuery.Count() > 0) { result = new CustomerAccountsVM() { Customer = customerQuery.First(), Accounts = accountQuery.ToList() }; } } return(result); }