public static Account LoginOrRegister(Account currentUser) { UIHelpers.Clear(); Console.WriteLine("\tWhat would you like to do?\n\n\t\t(L) - Login\n\t\t(R) - Register "); Console.Write("\n\tSelection: "); ConsoleKey loginOrRegisterResponse = Console.ReadKey().Key; Console.Write("\x1B[1D" + "\x1B[1P" + loginOrRegisterResponse.ToString().ToUpper()); if (loginOrRegisterResponse == ConsoleKey.L) { UIHelpers.Clear(); currentUser = LoginController.LoginEmail(loginAttempts); } else if (loginOrRegisterResponse == ConsoleKey.R) { UIHelpers.Clear(); UIHelpers.WarningColor(); Console.WriteLine("\tLet's get an account setup for you!"); UIHelpers.ResetColor(); currentUser = RegisterController.Register(RegistrationEnum.RegisterEmail); } else { UIHelpers.DangerColor(); Console.WriteLine("\n\tThat is an invalid entry. Please select 'L' to Login or 'R' to Register.\n"); System.Threading.Thread.Sleep(1000); UIHelpers.ResetColor(); currentUser = null; LoginOrRegister(currentUser); } return(currentUser); }
//Login for already registed user, sends back to LoginEmail public static Account LoginPassword(int loginAttempts, Account userLoggingIn) { if (loginAttempts <= maxLoginAttempts) { Console.Write("\tPlease enter your password: "******"\n"); UIHelpers.DangerColor(); Console.WriteLine("\tThat password is incorrect. You have " + (maxLoginAttempts - loginAttempts) + " attempt(s) remaining."); UIHelpers.ResetColor(); loginAttempts++; return(LoginPassword(loginAttempts, userLoggingIn)); } } else { FailedLogin(); currentUser = null; return(Program.LoginOrRegister(currentUser)); } return(AccountMenuView.AccountMainMenu(userLoggingIn)); }
//Email entry method for already registered user //Returns currentUser to LoginOrRegister public static Account LoginEmail(int loginAttempts) { //Limit login attempts to 3 if (loginAttempts <= maxLoginAttempts) { Console.Write("\tPlease enter your email address: "); string username = Console.ReadLine(); if (TheBanc.UserAccounts.Exists(i => i.AccountEmailAddressAndUsername == username)) { //Set currentUser to the List index of userAccounts for the given emailAddress Account userLoggingIn = TheBanc.UserAccounts[TheBanc.UserAccounts.FindIndex(i => i.AccountEmailAddressAndUsername == username)]; currentUser = LoginPassword(loginAttempts, userLoggingIn); } else { Console.WriteLine("\n"); UIHelpers.DangerColor(); Console.WriteLine("\tWe can't find an account associated with that email address.\n\tYou have " + (maxLoginAttempts - loginAttempts) + " attempt(s) remaining."); UIHelpers.ResetColor(); loginAttempts++; return(LoginEmail(loginAttempts)); } } else { FailedLogin(); currentUser = null; return(Program.LoginOrRegister(currentUser)); } return(currentUser); }
//Helper Method for already registered user failing login public static void FailedLogin() { UIHelpers.DangerColor(); Console.Write("\n\tWe are sorry. You have failed logging in 3 times.\n\tPlease try again later or contact customer support.\n\n\tPress any key to exit."); UIHelpers.ResetColor(); Console.ReadKey(); UIHelpers.Clear(); }
//Method helper for common aspects of making a transaction public static Account TransactionHelper(Account userMakingTransaction, string typeOfTransaction, decimal transAmount, bool isInitialDeposit) { Console.Write("\n\tYou are "); if(typeOfTransaction == "Deposit") { Console.Write("depositing"); } else { UIHelpers.DangerColor(); Console.Write("withdrawing"); UIHelpers.ResetColor(); } Console.Write(" {0:C} is that correct? (Y\\N\\x) ", transAmount); ConsoleKey verifyTranactionAmount = Console.ReadKey().Key; Console.Write("\x1B[1D" + "\x1B[1P" + verifyTranactionAmount.ToString().ToUpper()); if (verifyTranactionAmount == ConsoleKey.Y) { Console.Write("\n"); var transaction = new TransactionModel(typeOfTransaction, transAmount); userMakingTransaction.CustomerFinancialInformation.AccountBalance += (decimal)transAmount; //Insert over add to list //This way, [0] is always the last item userMakingTransaction.CustomerFinancialInformation.AccountTransactions.Insert(0, transaction); TransactionReceipt(userMakingTransaction); } else if (verifyTranactionAmount == ConsoleKey.X) { if(isInitialDeposit) { return RegisterController.FinancialAccountSetup(userMakingTransaction); } UIHelpers.WarningColor(); Console.WriteLine("\n\tCanceling the transacation and returning to Account Main Menu."); System.Threading.Thread.Sleep(2500); return AccountMainMenu(userMakingTransaction); } else { return MakingATransaction(userMakingTransaction, typeOfTransaction, isInitialDeposit); } return userMakingTransaction; }
//Seems like helper functions could simplify this public static Account MakingATransaction(Account userMakingTransaction, string typeOfTransaction = "Deposit", bool isInitialDeposit = false) { decimal initialDeposit; decimal depositAmount; decimal withdrawalAmount; string amountStr; bool success; decimal currentAccountBalance = userMakingTransaction.CustomerFinancialInformation.AccountBalance; if (typeOfTransaction == "Withdrawal") { if (currentAccountBalance > 5m) { UIHelpers.Clear(); Console.Write("\t('X + Return' to Cancel)"); Console.WriteLine("\n\tYour current balance is: {0:C}", currentAccountBalance); Console.Write("\n\tHow much would you like to "); UIHelpers.DangerColor(); Console.Write("withdraw"); UIHelpers.ResetColor(); Console.Write("? "); amountStr = Console.ReadLine(); if (amountStr.ToUpper() == "X") { CancelTransaction(); return AccountMainMenu(userMakingTransaction); } success = decimal.TryParse(amountStr, out withdrawalAmount); withdrawalAmount = Math.Abs(withdrawalAmount) * -1; if (success && (currentAccountBalance + withdrawalAmount >= 5m) && withdrawalAmount != 0m) { TransactionHelper(userMakingTransaction, typeOfTransaction, withdrawalAmount, false); } else { UIHelpers.DangerColor(); Console.WriteLine("\n\tOOPS! You don't have enough money to withdraw {0:C}.", withdrawalAmount); Console.WriteLine("\n\tYou must keep an account balance of at least $5.00."); Console.Write("\tPress 'Spacebar' to try again..."); UIHelpers.ResetColor(); ConsoleKey tryWithdrawalAgain = Console.ReadKey().Key; if (tryWithdrawalAgain == ConsoleKey.Spacebar) { return MakingATransaction(userMakingTransaction, typeOfTransaction, isInitialDeposit); } } } else { UIHelpers.DangerColor(); Console.WriteLine("\n\tOOPS! You don't have enough money to make a withdrawal."); Console.WriteLine("\n\tYou must keep an account balance of at least $5.00."); Console.Write("\tPress 'Spacebar' to return to Account Main Menu."); UIHelpers.ResetColor(); ConsoleKey returnToMainMenu = Console.ReadKey().Key; if (returnToMainMenu == ConsoleKey.Spacebar) { return AccountMainMenu(userMakingTransaction); } } } //Coming from Registration else if (isInitialDeposit) { Console.Write("\n\t('X + Return' to Cancel)"); Console.Write("\n\tHow much would you like to deposit? "); amountStr = Console.ReadLine(); if (amountStr.ToUpper() == "X") { CancelTransaction(); return RegisterController.FinancialAccountSetup(userMakingTransaction); } success = decimal.TryParse(amountStr, out initialDeposit); if (success && initialDeposit >= 5m) { TransactionHelper(userMakingTransaction, typeOfTransaction, initialDeposit, true); } else { UIHelpers.DangerColor(); Console.WriteLine("\n\tPlease open account with at least $5.00"); UIHelpers.ResetColor(); return MakingATransaction(userMakingTransaction, typeOfTransaction, isInitialDeposit); } } // end initial deposit //Coming from Account Menu else //general deposit { UIHelpers.Clear(); Console.Write("\t('X + Return' to Cancel)"); Console.WriteLine("\n\tYour current balance is: {0:C}", currentAccountBalance); Console.Write("\n\tHow much would you like to deposit? "); amountStr = Console.ReadLine(); if (amountStr.ToUpper() == "X") { CancelTransaction(); return AccountMainMenu(userMakingTransaction); } success = decimal.TryParse(amountStr, out depositAmount); if (success && depositAmount >= 0m) { TransactionHelper(userMakingTransaction, typeOfTransaction, depositAmount, false); } else { UIHelpers.DangerColor(); Console.WriteLine("\n\tPlease deposit more than $0.00"); UIHelpers.ResetColor(); return MakingATransaction(userMakingTransaction, typeOfTransaction, isInitialDeposit); } }// end general deposit return userMakingTransaction; }//End MakingTransaction Method