private static void Deposit(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Deposit Menu"; Console.WriteLine($"User:{username}\tYou pressed 3. Deposit to user's bank account\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again."); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //available users var account = new InternalAccount(); var users = account.GetUsernames(); //deposit data input Console.WriteLine("Please insert the username of the account you want to deposit to and the amount you want to deposit."); Console.WriteLine("These are the available users:"); foreach (var item in users) { if (item != username) { Console.WriteLine($"- {item}"); } } if (account.IsUserAdmin(username)) { Console.WriteLine("To deposit the same amount to all accounts type [all] in place of username."); } Console.Write("Username: "******"Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); //If admin and input all if (account.IsUserAdmin(username) && otherUsername.ToLower() == "all") { //Input validation for all var adminAmount = (users.Count - 1) * amount; Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; continue; } else if (!account.HasSufficientBalance(username, adminAmount)) { message = "Insufficient account balance."; continue; } //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAll(username, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } //Input validation for user Console.WriteLine(); if (!account.IsUserValid(otherUsername)) { message = "User not found."; } else if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (username == otherUsername) { message = "Cannot deposit to your account."; } else if (account.IsUserAdmin(otherUsername)) { message = "Cannot deposit to Cooperative’s internal bank account. \nTo deposit to Cooperative’s internal bank account go back to Main Menu."; } else if (!account.HasSufficientBalance(username, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAccount(username, otherUsername, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
private static void WithdrawMenu(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Withdraw Menu"; Console.WriteLine($"User:{username}\tYou pressed 4. Withdraw from account\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again."); // You have {tries} tries.\n"); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //available users var account = new InternalAccount(); var users = account.GetUsernames(); //withdraw data input Console.WriteLine("Please insert the username of the account you want to withdraw from and the amount you want to withdraw."); Console.WriteLine("These are the available users:"); foreach (var item in users) { Console.WriteLine($"- {item}"); } Console.WriteLine("To withdraw the same amount to from all accounts type [all] in place of username."); Console.Write("Username: "******"Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); // if admin from all if (account.IsUserAdmin(username) && otherUsername.ToLower() == "all") { //Input validation for all Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; continue; } var suffBalance = true; foreach (var unames in users) { if (!account.HasSufficientBalance(unames, amount)) { message = "Insufficient account balance."; suffBalance = false; continue; } } if (!suffBalance) { message = "Insufficient account balance."; continue; } //Successful input Console.WriteLine("\nProcessing your request.."); account.WithdrawFromAll(username, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } //Input validation Console.WriteLine(); if (!account.IsUserValid(otherUsername)) { message = "User not found."; } else if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (username == otherUsername) { message = "Cannot withdraw from Cooperative's internal bank account."; } else if (!account.HasSufficientBalance(otherUsername, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.Withdraw(otherUsername, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
public static string DisplayLogin(string connectionString) { var message = ""; for (var tries = 3; tries > 0; tries--) { Console.Clear(); Console.Title = "Internal Bank System - Login"; Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Welcome to the Internal Bank System of Cooperative Company !"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; //error messages if (tries < 3 && tries > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine($"{message} Please try again. You have {tries} tries."); Console.ForegroundColor = ConsoleColor.White; } //username and password input Console.WriteLine(); Console.WriteLine("Enter your username and password to login to your account."); Console.Write("Username: "******"Password: "******"User not found."; } else if (!account.IsPasswordValid(username, password)) { message = "Invalid entry."; } else { //Successful login Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Login Successful!"); Console.ForegroundColor = ConsoleColor.White; System.Threading.Thread.Sleep(500); return(username); } } //after 3 fails application displays message and closes. return(null); }