Exemple #1
0
        private static void SendMoney()
        {
            int finish = -1;

            do
            {
                List <Account> allUsers = transferService.GetAllUsers(UserService.GetUserId());
                PrintUsers(allUsers);
                Console.Write("Please enter ID of user you wish to transfer money to: (0 to exit) ");

                int toAccount = -1;
                if (!int.TryParse(Console.ReadLine(), out toAccount))
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Invalid entry.  Please enter a number. ");
                    SomethingWentWrong();
                    Console.Clear();
                }
                else if (toAccount == 0)
                {
                    Console.Clear();
                    break;
                }

                if (toAccount > 0)
                {
                    if (!IsValidUserId(allUsers, toAccount))
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Invalid Id. Please enter correct ID number. ");
                        SomethingWentWrong();
                    }
                    Console.Write("Please enter amount to transfer: $");
                    decimal amount = -1;
                    if (!decimal.TryParse(Console.ReadLine(), out amount))
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("Invalid entry. Please input numbers only.");
                        SomethingWentWrong();
                        toAccount = -1;
                    }
                    Transfer newTransfer = new Transfer();
                    newTransfer.account_From_ID  = UserService.GetUserId();
                    newTransfer.account_To_ID    = toAccount;
                    newTransfer.AmountToTransfer = amount;

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