Beispiel #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)
                {
                    double balance = accountService.GetBalance();
                    consoleService.PrintBalance(balance);
                    MenuSelection();
                }
                else if (menuSelection == 2)
                {
                    List <TransferClient> transfers = transferService.GetTransfers();
                    consoleService.PrintTransfers(transfers);
                    int id = -1;
                    while (id == -1)
                    {
                        id = consoleService.PromptForTransferID("view");
                        if (id == 0)
                        {
                            MenuSelection();
                        }
                    }
                    consoleService.PrintTransferDetails(id, transfers);
                    MenuSelection();
                }
                else if (menuSelection == 3)
                {
                    List <TransferClient> transfers = transferService.GetPendingTransfers();
                    consoleService.PrintPendingTransfers(transfers);
                    if (transfers.Count != 0)
                    {
                        int id = -1;
                        while (id == -1)
                        {
                            id = consoleService.PromptForTransferID("approve or reject");
                            if (id == 0)
                            {
                                MenuSelection();
                            }
                        }
                        int newStatus = consoleService.PromptForApproval();
                        if (newStatus == 0)
                        {
                            MenuSelection();
                        }
                        double         currentBalance = accountService.GetBalance();
                        TransferClient returnTransfer = transferService.UpdateTransfer(id, transfers, newStatus, currentBalance);
                        if (returnTransfer != null)
                        {
                            consoleService.PrintResult(returnTransfer.Status);
                        }
                    }
                    MenuSelection();
                }
                else if (menuSelection == 4)
                {
                    List <UserDTO> list = accountService.GetUsers();
                    consoleService.PrintUsers(list);
                    int id = -1;
                    while (id == -1)
                    {
                        id = consoleService.PromptForUserId(list, "send to");
                        if (id == 0)
                        {
                            MenuSelection();
                        }
                    }
                    double amount = -1;
                    while (amount == -1)
                    {
                        amount = consoleService.PromptForAmount("send");
                        if (amount == 0)
                        {
                            MenuSelection();
                        }
                    }
                    if (amount > accountService.GetBalance())
                    {
                        Console.WriteLine("\nYou don't have enough money to transfer.");
                        MenuSelection();
                    }
                    TransferClient returnTransfer = transferService.SendTransfer(id, amount);
                    if (returnTransfer != null)
                    {
                        consoleService.PrintResult(returnTransfer.Status);
                    }
                    MenuSelection();
                }
                else if (menuSelection == 5)
                {
                    List <UserDTO> list = accountService.GetUsers();
                    consoleService.PrintUsers(list);
                    int id = -1;
                    while (id == -1)
                    {
                        id = consoleService.PromptForUserId(list, "request from");
                        if (id == 0)
                        {
                            MenuSelection();
                        }
                    }
                    double amount = -1;
                    while (amount == -1)
                    {
                        amount = consoleService.PromptForAmount("request");
                        if (amount == 0)
                        {
                            MenuSelection();
                        }
                    }
                    TransferClient pendingTransfer = transferService.RequestTransfer(id, amount);
                    if (pendingTransfer != null)
                    {
                        consoleService.PrintResult(pendingTransfer.Status);
                    }
                    MenuSelection();
                }
                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);
                }
            }
        }
Beispiel #2
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(UserService.GetToken());
                    Console.Write("Your current account balance is: $");
                    Console.WriteLine(accountService.GetBalanceOfAccount(UserService.GetUserId()));

                    //Console.WriteLine(user.GetUserId());
                }
                else if (menuSelection == 2)
                {
                    int accountId = UserService.GetUserId();
                    List <TransferDetails> transfers = transferService.GetTransfers(accountId);
                    Console.WriteLine($"\n\nWhere did my money go? \nWe would all like to know. \nNow you can view below \nhow your dough got so low:");
                    Console.WriteLine($"------------------------------------------");
                    Console.WriteLine("\nTransfers \nID        From/To        Amount");
                    Console.WriteLine($"------------------------------------------");
                    foreach (TransferDetails tD in transfers)
                    {
                        Console.WriteLine($"{tD.ID}".PadRight(10) + $"To:  {tD.ToUser}".PadRight(17) + $"$ {tD.Amount}");
                    }
                    Console.WriteLine("\nWhat do IDs like to chase?... (press enter or you will never know)");
                    string nothing = Console.ReadLine();
                    Console.WriteLine("Their IDetails!\n... . . . . .  .  .  .   .   .   ");
                    Console.WriteLine("\nTo view the details from a transfer enter the ID number. To return to the main menu press 0.");
                    int userInput = int.Parse(Console.ReadLine());
                    if (userInput > 0)
                    {
                        transferService.GetTransfer(accountId, userInput);
                    }
                    else
                    {
                        Console.WriteLine("Sorry, that's not a valid transfer ID");
                    }
                }

                else if (menuSelection == 3)
                {
                }


                else if (menuSelection == 4)
                {
                    Console.WriteLine("Here is a list of Users and Ids available to send TEnmo Bucks to: ");
                    transferService.GetUsers();
                    Transfer transferAttempt = consoleService.PromptForTransferData();

                    if (transferAttempt == null || !transferAttempt.IsValid)
                    {
                        Console.WriteLine("Transfer failed - incorrect data entered.");
                    }

                    else
                    {
                        TransferDetails completedTransfer = transferService.TransferRequest(transferAttempt);
                        if (completedTransfer != null)
                        {
                            Console.WriteLine("Transfer successful.");
                            Console.WriteLine($"Transfer details: {completedTransfer.ToUser}, {completedTransfer.Amount} ");
                        }
                        else
                        {
                            Console.WriteLine("Transfer failed.");
                        }
                    }
                }


                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("Ok, come back with more munny soon!");
                    Environment.Exit(0);
                }
            }
        }
Beispiel #3
0
        private static void ViewTransfers()
        {
            Console.Clear();
            List <ReturnTransfer> transfers = transferService.GetTransfers(UserService.GetUserId());

            if (transfers == null || transfers.Count == 0)
            {
                Console.WriteLine("Sorry we couldn't find any transfers");
                Console.WriteLine("Press enter to return");
                Console.ReadLine();
                return;
            }
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("Transfers");
            Console.Write("ID");
            Console.Write("From/To".PadLeft(17));
            Console.WriteLine("Amount".PadLeft(17));
            Console.WriteLine("-------------------------------------------");

            foreach (ReturnTransfer transfer in transfers)
            {
                if (transfer.Transfer_status_id == 2)
                {
                    Console.Write($"{transfer.Transfer_id}".PadRight(10));
                    if (transfer.FromName == UserService.GetUserName())
                    {
                        Console.Write("To: ".PadRight(6));
                        Console.Write($"{transfer.ToName}");
                        Console.WriteLine($"{transfer.Amount:C2}".PadLeft(15));
                    }
                    else
                    {
                        Console.Write("From: ");
                        Console.Write($"{transfer.FromName}");
                        Console.WriteLine($"{transfer.Amount:C2}".PadLeft(15));
                    }
                }
            }
            Console.WriteLine("---------");
            bool validTransfer = false;

            do
            {
                Console.Write("Please enter the transfer ID to view details (0 to cancel): ");
                string userInput = Console.ReadLine().Trim();

                if (userInput == "0")
                {
                    Console.Clear();
                    return;
                }
                try
                {
                    ReturnTransfer returnTransfer = transferService.GetTransfer(Convert.ToInt32(userInput));
                    if (returnTransfer.Transfer_id != 0)
                    {
                        Console.WriteLine("-------------------------------------------");
                        Console.WriteLine("Transfer Details");
                        Console.WriteLine("-------------------------------------------");
                        Console.WriteLine($"Id: {returnTransfer.Transfer_id}");
                        Console.WriteLine($"From: {returnTransfer.FromName}");
                        Console.WriteLine($"To: {returnTransfer.ToName}");
                        Console.WriteLine($"Type: {returnTransfer.TransferType}");
                        Console.WriteLine($"Status: {returnTransfer.TransferStatus}");
                        Console.WriteLine($"Amount: {returnTransfer.Amount:C2}");
                        Console.WriteLine("-------------------------------------------");
                        Console.WriteLine("Please press enter to return");
                        Console.ReadLine();
                        Console.Clear();
                        validTransfer = true;
                    }
                    else
                    {
                        Console.WriteLine("Please select a valid transfer.");
                    }
                }
                catch
                {
                    Console.WriteLine("Please select a valid transfer");
                }
            } while (!validTransfer);
        }