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; } } }
private static void ViewAccounts(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - View user's Account"; Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\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(); //username input Console.WriteLine("Please insert the username of the account you want to view."); Console.WriteLine("These are the available users:"); foreach (var item in users) { Console.WriteLine($"- {item}"); } Console.WriteLine("To view all accounts type [all] in place of username."); Console.Write("Username: "******"all") { //success Console.WriteLine("\nProcessing your request.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\n"); Console.WriteLine("------------------------------------------------------------"); foreach (var item in users) { Console.WriteLine(account.ViewAccount(item)); Console.WriteLine("------------------------------------------------------------"); } GoToMainMenu(); return; } //input validation if (!users.Contains(otherUsername)) { message = "Invalid input. User not found."; } else { //success Console.WriteLine("\nProcessing your request.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\n"); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(account.ViewAccount(otherUsername)); Console.WriteLine("------------------------------------------------------------"); GoToMainMenu(); return; } } }