Beispiel #1
0
        private static void RequestMoney()
        {
            int finish = -1;

            do
            {
                List <Account> allUsers = transferService.GetAllUsers(UserService.GetUserId());
                PrintUsers(allUsers);
                Console.Write("Please enter ID of user you wish to request money from: ");
                int fromAccount = -1;
                if (!int.TryParse(Console.ReadLine(), out fromAccount))
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Invalid entry.  Please enter a number. ");
                    SomethingWentWrong();
                    Console.Clear();
                }
                if (fromAccount > 0)
                {
                    if (!IsValidUserId(allUsers, fromAccount))
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Invalid Id. Please enter correct ID number. ");
                        SomethingWentWrong();
                    }
                    Console.Write("Please enter amount to request: $");
                    decimal amount = -1;
                    if (!decimal.TryParse(Console.ReadLine(), out amount))
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Invalid entry. Please input numbers only.");
                        SomethingWentWrong();
                        fromAccount = -1;
                    }
                    Transfer newTransfer = new Transfer();
                    newTransfer.account_From_ID  = fromAccount;
                    newTransfer.account_To_ID    = UserService.GetUserId();
                    newTransfer.AmountToTransfer = amount;

                    if (amount > 0)
                    {
                        if (transferService.RequestMoney(newTransfer))
                        {
                            Console.WriteLine();
                            Console.WriteLine("--------------------------------------------------------------");
                            Console.WriteLine("Transfer Posted.  ");
                            Console.WriteLine("--------------------------------------------------------------");
                            System.Threading.Thread.Sleep(3000);
                            Console.Clear();
                            fromAccount = -1;
                            finish++;
                        }
                        else
                        {
                            Console.WriteLine("Insufficient Funds.");
                            System.Threading.Thread.Sleep(2000);
                            fromAccount = -1;
                        }
                    }
                }
            } while (finish != 0);
        }