private static void DepositToAdmin(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Deposit Menu"; Console.WriteLine($"User:{username}\tYou pressed 2. Deposit to Cooperative’s internal bank 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++; //deposit data input Console.WriteLine("Please insert the amount you want to deposit."); Console.Write("Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); //Input validation var account = new InternalAccount(); Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (!account.HasSufficientBalance(username, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAccount(username, "admin", amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
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; } } }