Beispiel #1
0
        static void ActionMenu(List <Account> list)
        {
            int optionCount = list.Count;

            Console.WriteLine("Count: =" + optionCount);
            int count = 1;
            int option;

            do
            {
                Console.WriteLine("\t*-------------Account Options-------------*");
                Console.WriteLine("Choose one of the following Accounts to withdraw, desposit, transfer, or view transactions (Enter 0 to go back)");
                foreach (var acct in list)
                {
                    Console.WriteLine($"{count}) {acct.ToString()}");
                    count++;
                }
                Console.Write("Choose Account: ");
                string str = Console.ReadLine();
                count = 1;
                if (!int.TryParse(str, out option))
                {
                    Console.WriteLine($"Error: [{str}] is not a option");
                }
                else if (option == 0)
                {
                    break; //brake out of loop to go back to user menu
                }
                else if (option < 1 || option > optionCount)
                {
                    Console.WriteLine($"Error: {option} is not an option");
                }
                else
                {
                    int     opt;
                    Account acct = list[option - 1];
                    do
                    {
                        Console.WriteLine("\t*-------------Action Options-------------*");
                        Console.WriteLine("Choose one of the following options");
                        Console.WriteLine("1) Withdraw From Account");
                        Console.WriteLine("2) Deposit Into Account");
                        Console.WriteLine("3) Transfer Between Account");
                        Console.WriteLine("4) Close Account");
                        Console.WriteLine("5) View Account Transaction History");
                        Console.WriteLine("0) Go Back");
                        Console.Write("Enter Option: ");
                        string st = Console.ReadLine();
                        if (!int.TryParse(st, out opt))
                        {
                            Console.WriteLine($"Error: [{st}] is not a option");
                        }
                        else if (opt == 0)
                        {
                            break;
                        }
                        else if (opt < 1 || opt > 5)
                        {
                            Console.WriteLine($"Error: {opt} is not an option");
                        }
                        else
                        {
                            switch (opt)
                            {
                            case 1:
                                decimal amount = 0;
                                Console.Write("Enter a Withdraw Amount: ");
                                string amt = Console.ReadLine();
                                if (!decimal.TryParse(amt, out amount))
                                {
                                    Console.WriteLine($"Error: [{amt}] is not a number");
                                }
                                else if (acct.Withdraw(amount))
                                {
                                    Console.WriteLine("[Withdraw was Successful]");
                                    Console.WriteLine(acct.ToString());
                                }
                                break;

                            case 2:
                                decimal amount2 = 0;
                                Console.Write("Enter a Deposit Amount: ");
                                string amt2 = Console.ReadLine();
                                if (!decimal.TryParse(amt2, out amount2))
                                {
                                    Console.WriteLine($"Error: [{amt2}] is not a number");
                                }
                                else if (acct.Deposit(amount2))
                                {
                                    Console.WriteLine("[Deposit was Successful]");
                                    Console.WriteLine(acct.ToString());
                                }
                                break;

                            case 3:
                                if (list.Count == 1)
                                {
                                    Console.WriteLine("Error: Cannot transfer with only one account");
                                }
                                else
                                {
                                    Account destAcct = GetAccount(list, acct);
                                    decimal amount3  = 0;
                                    if (destAcct != null)
                                    {
                                        Console.Write("Enter a Transfer Amount: ");
                                        string amt3 = Console.ReadLine();
                                        if (!decimal.TryParse(amt3, out amount3))
                                        {
                                            Console.WriteLine($"Error: [{amt3}] is not a number");
                                        }
                                        else
                                        {
                                            acct.TransferBetweenAccounts(destAcct, amount3);
                                            //Console.WriteLine("[Transfer was Successful]");
                                            Console.WriteLine(acct.ToString());
                                        }
                                    }
                                }
                                break;

                            case 4:
                                acct.CloseAccount();
                                break;

                            case 5:
                                PrintTransaction(acct.accountTransactions);
                                break;

                            default:
                                break;
                            }
                            // Console.WriteLine("GOT TO ACTions");
                        }
                    } while (true);
                }
            } while (true);
        }