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.WriteLine($"Your current account balance is: ${apiService.GetBalance()}"); } else if (menuSelection == 2) { List <API_Transfer> transfers = apiService.ListTransfers(); if (transfers != null && transfers.Count > 0) { consoleService.WriteTransferList(transfers); int id = consoleService.TransferToDetail(transfers); API_Transfer transfer = apiService.GetTransfer(id); consoleService.GetTransferDetails(transfer); } } else if (menuSelection == 3) { List <API_Transfer> transfers = apiService.ListTransfers(); if (transfers != null && transfers.Count > 0) { consoleService.WritePendingTransferList(transfers); } } else if (menuSelection == 4) { List <API_User> users = apiService.ListUsers(); int userID = UserService.GetUserId(); API_Account accountFrom = apiService.GetAccount(userID); if (users != null && users.Count > 0) { API_Transfer transfer = consoleService.StartTransfer(users); if (transfer.TransferAmount > accountFrom.Balance) { Console.WriteLine("Insufficient Funds"); } else { API_Transfer updatedTransfer = apiService.DoTransfer(transfer); apiService.UpdateBalance(updatedTransfer); Console.WriteLine("Amount has been transferred"); } } } else if (menuSelection == 5) { List <API_User> users = apiService.ListUsers(); if (users != null && users.Count > 0) { API_Transfer transfer = consoleService.RequestTransfer(users); apiService.DoTransfer(transfer); Console.WriteLine("Request Sent."); } } 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) { Account accounts = api.GetBalance(); Console.Write("Your current balance is: $" + accounts.Balance + "."); } else if (menuSelection == 2) { Transfer transaction = new Transfer(); int id = UserService.GetUserId(); List <Transfer> transfers = api.GetTransactionsByID(id); foreach (Transfer transfer in transfers) { Console.WriteLine(transfer.AccountFrom + transfer.AccountTo + transfer.Amount + transfer.TransferId); } } else if (menuSelection == 3) { } else if (menuSelection == 4) { List <User> newUser = api.GetUsers(); 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"); 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.WriteLine("Your current balance is: $" + API_BASE_URL.GetBalance()); } else if (menuSelection == 2) { PrintTransferDetails(API_BASE_URL.GetListOfTransfers());//list user's names } else if (menuSelection == 3) { PrintPendingRequests(API_BASE_URL.GetPendingTransfers()); List <int> pendingTransferIds = new List <int>(); foreach (Transfer t in API_BASE_URL.GetPendingTransfers()) { pendingTransferIds.Add(t.TransferId); } int transferId = PromptForTransferId(pendingTransferIds); if (transferId != 0) { int acceptOrReject = AcceptReject(); if (acceptOrReject == 1) { API_BASE_URL.ReceivePendingRequest(transferId); } else if (acceptOrReject == 2) { API_BASE_URL.RejectTransferRequest(transferId); } } } else if (menuSelection == 4) { PrintTEBucks(API_BASE_URL.GetUsers()); int id = PromptForUserIDSelection(); decimal amount = 0; if (id != 0) { amount = PromptForAmountSelection(); } API_BASE_URL.TransferFunds(id, amount); } else if (menuSelection == 5) { PrintTEBucks(API_BASE_URL.GetUsers()); int id = PromptForUserIDSelection(); decimal amount = 0; if (id != 0) { amount = PromptForAmountSelection(); API_BASE_URL.RequestMoney(id, amount); } } 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"); //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 = 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); } } }