private static void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); Console.WriteLine("3: View your pending requests"); Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); menuSelection = CLIHelper.GetNumberInRange(0, 6); if (menuSelection == 1) { Account account = apiService.GetAccount(); if (account != null) { Console.WriteLine($"Your current account balance is: {account.Balance.ToString("C2")}"); } } else if (menuSelection == 2) { List <TransferWithDetails> transferHistory = apiService.GetTransferHistory(); var allTransferIDs = new List <int>(); allTransferIDs.Add(0); Console.WriteLine("-------------------------------------------"); Console.WriteLine("Transfer IDs From/To Amount"); Console.WriteLine("-------------------------------------------"); foreach (var item in transferHistory) { if (item.TransferId < 10) { if (item.FromUser == UserService.GetUsername()) { Console.WriteLine($"0{item.TransferId} To: {item.ToUser} {item.Amount}"); } else { Console.WriteLine($"0{item.TransferId} From: {item.FromUser} {item.Amount}"); } } else { if (item.FromUser == UserService.GetUsername()) { Console.WriteLine($"{item.TransferId} To: {item.ToUser} {item.Amount}"); } else { Console.WriteLine($"{item.TransferId} From: {item.FromUser} {item.Amount}"); } } allTransferIDs.Add(item.TransferId); } Console.WriteLine("-------------------------------------------"); Console.WriteLine("Please enter transfer ID to view details (0 to cancel):"); int transferId = CLIHelper.GetNumberInList(allTransferIDs); if (transferId != 0) { TransferWithDetails transfer = apiService.GetTransferById(transferId); Console.WriteLine("-------------------------------------------"); Console.WriteLine("Transfer details"); Console.WriteLine("-------------------------------------------"); Console.WriteLine($"ID: {transfer.TransferId}"); Console.WriteLine($"From: {transfer.FromUser}"); Console.WriteLine($"To: {transfer.ToUser}"); Console.WriteLine($"Type: {transfer.TransferType}"); Console.WriteLine($"Status: {transfer.TransferStatus}"); Console.WriteLine($"Amount: {transfer.Amount}"); } else { Console.WriteLine("Returning to the main menu."); } } else if (menuSelection == 3) { } else if (menuSelection == 4) { List <API_User> users = apiService.ListUsers(); // list users to select from var allUserIDs = new List <int>(); // puts all users in list int currentUserId = UserService.GetUserId(); // gets current user id users.RemoveAt(currentUserId - 1); // remove current user from list Console.WriteLine("-------------------------------------------"); Console.WriteLine("User IDs Names"); Console.WriteLine("-------------------------------------------"); foreach (var item in users) // display users { Console.WriteLine($"{item.UserId} {item.Username}"); allUserIDs.Add(item.UserId); } Console.WriteLine("-------------------------------------------"); Console.WriteLine("Enter the ID of user you are sending to (0 to cancel):"); int receiverId = CLIHelper.GetNumberInList(allUserIDs); // make sure selection is in range if (receiverId != 0) { Console.WriteLine("Enter amount to send:"); decimal amount = CLIHelper.GetAmount(); // in range method TransferWithDetails result = apiService.SendMoney(receiverId, amount); // getting details from sendmoney & storing in "result" if (result != null) { // displaying transfer details Console.WriteLine("Transfer successful! :)"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("Transfer Details"); Console.WriteLine("-------------------------------------------"); Console.WriteLine($"ID: {result.TransferId}"); Console.WriteLine($"From: {result.FromUser}"); Console.WriteLine($"To: {result.ToUser}"); Console.WriteLine($"Type: {result.TransferType}"); Console.WriteLine($"Status: {result.TransferStatus}"); Console.WriteLine($"Amount: {result.Amount}"); } else { Console.WriteLine("Transfer not completed"); } } } else if (menuSelection == 5) { Console.WriteLine("Feature unavailable. Returning to main menu."); // not implemented } else if (menuSelection == 6) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Run(); //return to entry point } else { Console.WriteLine("Thank you for using TEnmo. Goodbye!"); Environment.Exit(0); } } }
private void ShowMainMenu() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); Console.WriteLine("3: View your pending requests"); Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else { switch (menuSelection) { case 1: GetBalance(authService.userId); break; case 2: GetTransfersByUserId(authService.userId); Console.WriteLine("Please enter the Transfer ID you'd like to see:"); int inputTransferId = Convert.ToInt32(Console.ReadLine()); GetTransferById(inputTransferId); break; case 3: Console.WriteLine("NOT IMPLEMENTED!"); // TODO: Implement me break; case 4: GetUsers(); Console.WriteLine(); Console.WriteLine("Please input the userID of the user you would like to send money to: "); int sendToUserId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("How many TE bucks would you like to send?"); decimal moneyAmount = Convert.ToDecimal(Console.ReadLine()); AddTransfer(authService.userId, sendToUserId, moneyAmount); break; case 5: Console.WriteLine("NOT IMPLEMENTED!"); // TODO: Implement me break; case 6: Console.WriteLine(); UserService.SetLogin(new API_User()); //wipe out previous login info return; default: Console.WriteLine("Goodbye!"); shouldExit = true; return; } } } }
private static void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); Console.WriteLine("3: View your pending requests"); Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else if (menuSelection == 1) { decimal?balance = apiService.GetAccountBalance(); if (balance != null) { decimal balanceAmount = (decimal)balance; Console.WriteLine($"Here's your account balance: {balanceAmount.ToString("C2")}"); } } else if (menuSelection == 2) { List <API_Transfer> transfers = apiService.GetTransfers(); if (transfers == null) { continue; } consoleService.PrintAllTransfers(transfers); int chosenID = consoleService.PromptForTransferID("get details"); Func <API_Transfer, bool> search = t => t.TransferID == chosenID; if (transfers.Any(search)) { API_Transfer transfer = transfers.Single(search); consoleService.PrintTransferDetails(transfer); } else if (chosenID != 0) { Console.WriteLine("The transfer ID you requested does not exist."); } } else if (menuSelection == 3) { List <API_Transfer> transfers = apiService.GetTransfers(); if (transfers == null) { continue; } consoleService.PrintPendingTransfers(transfers); int chosenID = consoleService.PromptForTransferID("approve or reject request"); int approvalOption; List <API_Transfer> pendingTransfers = transfers.Where(t => t.TransferStatus == TransferStatus.Pending).ToList(); Func <API_Transfer, bool> search = t => t.TransferID == chosenID; if (pendingTransfers.Any(search)) { API_Transfer pendingTransfer = pendingTransfers.Single(search); approvalOption = consoleService.PromptForApproval(); apiService.UpdateTransferStatus(pendingTransfer, approvalOption); } else if (chosenID != 0) { Console.WriteLine("The transfer ID you requested does not exist."); } } else if (menuSelection == 4) { List <API_User> users = apiService.GetOtherUsers(); if (users == null) { continue; } consoleService.PrintUsers(users); TransferType transferType = TransferType.Send; API_Transfer transfer = consoleService.PromptForTransferRequest(transferType); if (!users.Any(u => u.UserId == transfer.ToUserID)) { Console.WriteLine("The user ID you requested does not exist."); continue; } transfer.ToUserName = users.First(u => u.UserId == transfer.ToUserID)?.Username; apiService.SubmitTransferRequest(transfer); } else if (menuSelection == 5) { List <API_User> users = apiService.GetOtherUsers(); if (users == null) { continue; } consoleService.PrintUsers(users); TransferType transferType = TransferType.Request; API_Transfer transfer = consoleService.PromptForTransferRequest(transferType); if (!users.Any(u => u.UserId == transfer.FromUserID)) { Console.WriteLine("The user ID you requested does not exist."); continue; } transfer.FromUserName = users.First(u => u.UserId == transfer.FromUserID).Username; apiService.SubmitTransferRequest(transfer); } else if (menuSelection == 6) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Run(); //return to entry point } else { Console.WriteLine("Goodbye!"); Environment.Exit(0); } } }
private static void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); Console.WriteLine("3: View your pending requests"); Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else if (menuSelection == 1)//show user balance { Console.WriteLine(string.Format("{0:C}", api.GetBalance())); } else if (menuSelection == 2)//show logged in users transfers { List <Transfer> list = api.ShowTransfers(); string menuMessage = "\nEnter Transfer ID to see more details or 0 to return to main Menu: "; menuSelection = ShowTransferDetails(menuSelection, list, menuMessage); } else if (menuSelection == 3)//view logged in users pending requests { //grab lists of pending requests //use show transfers model but only show pending transfers instead of all transfers List <Transfer> list = api.ShowPendingRequests(); string menuMessage = "Please enter transfer ID to approve/reject (0 to cancel): "; menuSelection = ShowTransferDetails(menuSelection, list, menuMessage); } else if (menuSelection == 4)//send money to other users { /*Console.WriteLine(UserService.GetUserName()); /* this is debugger code that can be deleted once * option 5 is completed */ List <User> users = api.GetUsers(); //Get list of users users.RemoveAt(UserService.GetUserId() - 1); //remove current user from list of potential recipients string menuMessage = "Please select who you would like to transfer funds to or enter 0 to cancel the transfer: "; int recipient = MenuSelectionOptions(menuMessage, users); CreateNewTransfer(ref menuSelection, users, ref recipient); } else if (menuSelection == 5)//request money from other members { List <User> users = api.GetUsers(); //remove current user from list of potential recipients users.RemoveAt(UserService.GetUserId() - 1); string menuMessage = @"Please select who you would like to request funds from or " + "enter 0 to cancel the request: "; int sender = MenuSelectionOptions(menuMessage, users); if (sender == 0)//cancels/exits out of current operation { Console.WriteLine("transfer canceled"); menuSelection = -1; } else { CreateTransferRequest(ref sender); } } else if (menuSelection == 6) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Run(); //return to entry point } else if (menuSelection == 0) { Console.WriteLine("Goodbye!"); Environment.Exit(0); } else { Console.WriteLine("Please enter a valid menu selection"); menuSelection = -1; } } }
private void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); //view details through here Console.WriteLine("3: View your pending requests"); //ability to approve/reject through here Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: View list of users"); Console.WriteLine("7: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); try { if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else if (menuSelection == 1) { } else if (menuSelection == 2) { } else if (menuSelection == 3) { } else if (menuSelection == 4) { } else if (menuSelection == 5) { } else if (menuSelection == 6) { } else if (menuSelection == 7) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info return; //return to register/login menu } else if (menuSelection == 0) { Console.WriteLine("Goodbye!"); Environment.Exit(0); } else { Console.WriteLine("Please try again"); Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine("Error - " + ex.Message); Console.WriteLine(); } } }
private static void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); Console.WriteLine("3: View your pending requests"); Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else if (menuSelection == 1) { Account accounts = api.GetBalance(); Console.WriteLine("Your current balance is: " + accounts.Balance); } else if (menuSelection == 2) { Transfer transaction = new Transfer(); int id = UserService.GetUserId(); List <Transfer> transfers = api.AllTransactionsById(id); foreach (Transfer transfer in transfers) { Console.WriteLine(transfer.AccountFrom + " " + transfer.accountTo + " " + transfer.Amount + " " + transfer.TransferId); } int details = CLIHelper.GetInteger("Enter the ID of the transaction you would like to view. (0 to cancel)"); transaction = api.TransactionDetails(details); if (details == 0 || transaction == null) { MenuSelection(); } else if (details == transaction.TransferId) { int transactionId = transaction.TransferId; Console.WriteLine("id: " + transaction.TransferId); Console.WriteLine("From: " + transaction.AccountFrom); Console.WriteLine("To: " + transaction.accountTo); Console.WriteLine("Type: " + transaction.TransferTypeId); Console.WriteLine("Status: " + transaction.TransferStatusId); Console.WriteLine("Amount: " + transaction.Amount); } } else if (menuSelection == 3) { } else if (menuSelection == 4) { List <User> newUser = api.GetAllUsers(); foreach (User users in newUser) { Console.WriteLine(users.UserId.ToString() + " " + users.Username); } Program.Transaction(); } else if (menuSelection == 5) { } else if (menuSelection == 6) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Run(); //return to entry point } else { Console.WriteLine("Goodbye!"); Environment.Exit(0); } } }
private static void MenuSelection() { int menuSelection = -1; while (menuSelection != 0) { Console.WriteLine(""); Console.WriteLine("Welcome to TEnmo! Please make a selection: "); Console.WriteLine("1: View your current balance"); Console.WriteLine("2: View your past transfers"); //Sub menu needs to have "Transfer Details" Console.WriteLine("3: View your pending requests"); // Sub menu needs to have "Approve or reject pending transfer" where they can be approved/rejected with a "0" for cancel Console.WriteLine("4: Send TE bucks"); Console.WriteLine("5: Request TE bucks"); Console.WriteLine("6: Log in as different user"); Console.WriteLine("0: Exit"); Console.WriteLine("---------"); Console.Write("Please choose an option: "); if (!int.TryParse(Console.ReadLine(), out menuSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } else if (menuSelection == 1) { // View your current balance Console.WriteLine("-------------------------------------------"); Console.WriteLine($"Your current account balance is: ${APIService.GetUserBalance()}"); Console.WriteLine("-------------------------------------------"); } else if (menuSelection == 2) { List <TransferHistory> historyList = APIService.GetTransferHistory(); consoleService.HistorcialTransfers(historyList); } else if (menuSelection == 3) { //ConsoleService.PendingRequests(); // Still need to figure out return type. } else if (menuSelection == 4) { // Send TE bucks //Console.WriteLine("-------------------------------------------\n" + // "Users\nID\t\t\tName\n" + // "-------------------------------------------\n" + // /*$*/"{/*User ID*/}\t\t\t{/*User name*/}\n" + // Maybe replace with a list of users? // Shows misalligned until /*User ID*/ is replaced with a 2 or 3 digit interger // /*$*/"{/*User ID*/}\t\t\t{/*User name*/}\n" + // Maybe replace with a list of users? // Shows misalligned until /*User ID*/ is replaced with a 2 or 3 digit interger // "---------\n" + // "\n" + // "Enter ID of user you are sending to (0 to cancel):\n" + // "Enter amount:"); // Console.ReadLine() find ID to send money to consoleService.PrintUsers(APIService.GetUsers()); TransferDetails goodTransfer = APIService.PostTransfer(consoleService.PromptForTransferInfo()); consoleService.PrintTransferDetails(goodTransfer); } else if (menuSelection == 5) { // Request TE bucks Console.WriteLine("-------------------------------------------\n" + "Users\n" + "ID\t\t\tName\n" + "-------------------------------------------\n" + /*$*/ "{/*User ID*/}\t\t\t{/*User name*/}\n" + // Maybe replace with a list of users? /*$*/ "{/*User ID*/}\t\t\t{/*User name*/}\n" + // Maybe replace with a list of users? "---------\n" + "\n" + "Enter ID of user you are requesting from (0 to cancel):\n" + "Enter amount:"); } else if (menuSelection == 6) { // Log in as different user Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Run(); //return to entry point } else { // Exit Console.WriteLine("Goodbye!"); Environment.Exit(0); } } }