Ejemplo n.º 1
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 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);
                }
            }
        }