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"); //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: 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.GetBalance(); if (balance != decimal.MinValue) { Console.WriteLine("Your TE bucks balance is " + balance.ToString("C")); } } else if (menuSelection == 2) { List <Transfer> transfers = apiService.GetTransfers(); if (transfers != null) { consoleService.PrintTransfers(transfers); if (transfers.Count > 0) { int transferId = consoleService.PromptForTransferID("view"); if (transferId > 0) { Transfer transfer = apiService.GetTransfer(transferId); if (transfer != null) { consoleService.PrintTransfer(transfer); } } } } } else if (menuSelection == 3) { List <Transfer> transfers = apiService.GetPendingTransfers(); if (transfers != null) { consoleService.PrintTransfers(transfers); if (transfers.Count > 0) { string choice = consoleService.PromptForApproveOrReject(); if (choice != null) { int transferId = consoleService.PromptForTransferID(choice); if (transferId > 0) { if (choice == "approve") { Transfer transfer = apiService.ApproveTransfer(transferId); if (transfer.TransferStatus == TransferStatus.Approved) { Console.WriteLine("Approval was successful"); consoleService.PrintTransfer(transfer); } else { Console.WriteLine("Approval was not successful"); } } else if (choice == "reject") { Transfer transfer = apiService.RejectTransfer(transferId); if (transfer.TransferStatus == TransferStatus.Rejected) { Console.WriteLine("Rejection was successful"); consoleService.PrintTransfer(transfer); } else { Console.WriteLine("Rejection was not successful"); } } } } } } } else if (menuSelection == 4) { NewTransfer newTransfer = consoleService.PromptForTransfer(TransferType.Send); if (newTransfer != null) { Transfer addedTransfer = apiService.AddTransfer(newTransfer); if (addedTransfer != null) { consoleService.PrintTransfer(addedTransfer); } } } else if (menuSelection == 5) { NewTransfer newTransfer = consoleService.PromptForTransfer(TransferType.Request); if (newTransfer != null) { Transfer addedTransfer = apiService.AddTransfer(newTransfer); if (addedTransfer != null) { consoleService.PrintTransfer(addedTransfer); } } } 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) { 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) { decimal balance = api.GetBalance(); if (balance >= 0) { Console.WriteLine($"Your account balance is: ${balance}"); } } else if (menuSelection == 2) { List <Transfer> transferHistory = api.GetTransfers(); if (transferHistory != null && transferHistory.Count > 0) { consoleService.PrintTransfer(transferHistory); } Console.WriteLine($"Please enter transfer ID to view details (0 to cancel):"); if (!int.TryParse(Console.ReadLine(), out int transferSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } if (transferSelection > 0) { Transfer transferDetails = api.GetTransferDetails(transferSelection); consoleService.PrintTransferDetails(transferDetails); } else if (transferSelection == 0) { MenuSelection(); } // Pulls list with all transfers relating to user THEN hase menu to look at details of each transfer (5 & 6 From sample Screen) } else if (menuSelection == 3) { // Is part of optional use cases ( Step 8 on ReadMe ) } else if (menuSelection == 4) { List <Users> users = api.GetUsers(); if (users != null && users.Count > 0) { consoleService.PrintUsers(users); } Console.WriteLine("Enter ID of user you are sending to(0 to cancel):"); if (!int.TryParse(Console.ReadLine(), out int userSelection)) { Console.WriteLine("Invalid input. Please enter only a number."); } Console.WriteLine("Enter amount: "); if (!decimal.TryParse(Console.ReadLine(), out decimal amountToSend)) { Console.WriteLine("Invalid input. Please enter only a number."); } Transfer transfer = new Transfer { TransferTypeId = 2, TransferStatusId = 2, AccountFrom = UserService.GetUserId(), AccountTo = userSelection, Amount = amountToSend }; api.UpdateUserBalance(transfer); api.UpdateRecieverBalance(transfer); if (api.TransferRequest(transfer)) { Console.WriteLine("Ya boi got his money"); } else { Console.WriteLine("YOU ARE A FAILURE!"); } } else if (menuSelection == 5) { // Is part of option use cases ( Step 7 on the ReadMe ) } 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) { Console.Clear(); decimal balance = apiService.GetBalance(); Console.WriteLine($"Your current account balance is: {balance.ToString("C2")}"); Console.ReadLine(); Console.Clear(); } else if (menuSelection == 2) { Console.Clear(); List <TransferListObject> transfers = apiService.GetTransfers(); Transfer specific = null; int transferId = -1; while (specific == null && transferId == -1) { Console.WriteLine("----------------------------------------"); Console.WriteLine("Transfers"); Console.WriteLine($"ID\t\tFrom/To\t\tAmount"); Console.WriteLine("----------------------------------------"); foreach (TransferListObject transfer in transfers) { Console.WriteLine($"{transfer.TransferId}\t\t{transfer.ToFromUser} \t{transfer.Amount.ToString("C2")}"); } transferId = ConsoleService.GetInteger("\nPlease enter transfer ID to view details(0 to cancel): "); Console.Clear(); if (transferId != 0) { specific = apiService.GetSpecificTransfer(transferId); if (specific == null) { continue; } Console.WriteLine("----------------------------------------"); Console.WriteLine("Transfer Details"); Console.WriteLine("----------------------------------------"); Console.WriteLine($"Id: {specific.TransferId}"); string username = apiService.GetUsernameFromAccountNumber(specific.AccountFromId); Console.WriteLine($"From: {username}"); string otherUser = apiService.GetUsernameFromAccountNumber(specific.AccountToId); Console.WriteLine($"To: {otherUser}"); Console.WriteLine($"Type: {specific.TransferTypeId}"); Console.WriteLine($"Status: {specific.TransferStatusId}"); Console.WriteLine($"Amount: {specific.Amount.ToString("C2")}"); Console.ReadLine(); Console.Clear(); } else if (transferId == 0) { break; } } } else if (menuSelection == 3) { Console.Clear(); List <Transfer> transfers = apiService.GetPendingTransfers(); bool transferExists = false; int transferId = -1; while (!transferExists && transferId != 0) { Console.WriteLine("----------------------------------------"); Console.WriteLine("Pending Transfers"); Console.WriteLine($"ID\t\tTo\t\tAmount"); Console.WriteLine("----------------------------------------"); foreach (Transfer transfer in transfers) { string username = apiService.GetUsernameFromAccountNumber(transfer.AccountToId); Console.WriteLine($"{transfer.TransferId}\t\t{username}\t\t{transfer.Amount.ToString("C2")}"); } transferId = ConsoleService.GetInteger("\nPlease enter transfer ID to approve / reject(0 to cancel): "); if (transferId == 0) { Console.Clear(); break; } foreach (Transfer transfer in transfers) { if (transferId == transfer.TransferId) { transferExists = true; } } Console.Clear(); } if (transferId != 0) { int selection = ConsoleService.GetInteger("1: Approve\n2: Reject\n0: Don't approve or reject\n----------------------------------------\nPlease choose an option: "); Console.Clear(); UpdateTransfer uT = new UpdateTransfer(); bool wasSuccessful = false; if (selection == 1) { uT.TransferId = transferId; uT.isApproved = true; wasSuccessful = apiService.UpdatePendingTransfer(uT); } else if (selection == 2) { uT.TransferId = transferId; uT.isApproved = false; wasSuccessful = apiService.UpdatePendingTransfer(uT); } if (uT.isApproved && wasSuccessful) { Console.Clear(); Console.WriteLine("The transaction was approved."); } else if (uT.isApproved) { Console.Clear(); Console.WriteLine("Insufficient funds to complete the transaction."); } else if (!uT.isApproved && wasSuccessful) { Console.Clear(); Console.WriteLine("The transaction was successfully rejected."); } } } else if (menuSelection == 4) { int otherUserId = -1; decimal amount = -1; bool userExists = false; while (!userExists) { Console.Clear(); List <UserInfo> users = apiService.GetAllUsers(); Console.WriteLine("----------------------------------------"); Console.WriteLine("Users"); Console.WriteLine("ID \t\tName"); Console.WriteLine("----------------------------------------"); foreach (UserInfo user in users) { Console.WriteLine($"{user.UserId}\t\t{user.Username}"); } otherUserId = ConsoleService.GetInteger("Enter ID of user you are sending to (0 to cancel): "); foreach (UserInfo user in users) { if (otherUserId == user.UserId) { userExists = true; } } if (otherUserId == 0) { Console.Clear(); break; } else if (userExists) { while (amount < .01M) { amount = ConsoleService.GetDecimal("Enter amount: "); } ClientTransfer cT = new ClientTransfer(otherUserId, amount, false); bool wasSuccessful = apiService.SendMoney(cT); if (wasSuccessful) { Console.Clear(); string receiverName = ""; foreach (UserInfo user in users) { if (user.UserId == otherUserId) { receiverName = user.Username; } } Console.WriteLine($"Transfer of {amount.ToString("C2")} to {receiverName} was successful"); } else { Console.WriteLine("Transaction was not successful, please try again"); } } } } else if (menuSelection == 5) { int otherUserId = -1; decimal amount = -1; bool userExists = false; while (!userExists) { List <UserInfo> users = apiService.GetAllUsers(); Console.WriteLine("----------------------------------------"); Console.WriteLine("Users"); Console.WriteLine("ID \t\tName"); Console.WriteLine("----------------------------------------"); foreach (UserInfo user in users) { Console.WriteLine($"{user.UserId}\t\t{user.Username}"); } otherUserId = ConsoleService.GetInteger("Enter ID of user you are requesting from (0 to cancel): "); string receiverName = ""; foreach (UserInfo user in users) { if (otherUserId == user.UserId) { userExists = true; receiverName = user.Username; } } if (otherUserId == 0) { Console.Clear(); break; } else if (userExists) { while (amount < .01M) { amount = ConsoleService.GetDecimal("Enter amount: "); } ClientTransfer cT = new ClientTransfer(otherUserId, amount, true); bool wasSuccessful = apiService.SendMoney(cT); if (wasSuccessful) { Console.Clear(); Console.WriteLine($"Transfer of {amount.ToString("C2")} from {receiverName} was created successfully"); } else { Console.WriteLine("Transaction was not successful, please try again"); } } } } else if (menuSelection == 6) { Console.WriteLine(""); UserService.SetLogin(new API_User()); //wipe out previous login info Console.Clear(); Run(); //return to entry point } else { Console.Clear(); Console.WriteLine("Goodbye!"); Environment.Exit(0); } } }