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);
        }
Exemple #2
0
        private static void SendMoney()
        {
            bool   selectedUser = false;
            string sendToUser;

            do
            {
                List <OtherUser> otherUsers = accountService.RetrieveUsers();
                Console.Clear();
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Users");
                Console.Write("ID");
                Console.WriteLine("Name".PadLeft(15));
                Console.WriteLine("-------------------------------------------");
                foreach (OtherUser user in otherUsers)
                {
                    if (user.User_Id != UserService.GetUserId())
                    {
                        Console.Write($"{user.User_Id}");
                        Console.WriteLine($"{user.Username}".PadLeft(15));
                    }
                }
                Console.WriteLine("---------\n");
                Console.Write("Enter ID of the user you are sending to (0 to cancel): ");
                sendToUser = Console.ReadLine().Trim();
                if (Convert.ToInt32(sendToUser) == 0)
                {
                    Console.Clear();
                    return;
                }
                try
                {
                    if (accountService.GetBalance(Convert.ToInt32(sendToUser)) == -1)
                    {
                        Console.WriteLine("Please enter a valid user");
                    }
                    else
                    {
                        selectedUser = true;
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Please select a valid user ID");
                }
            } while (!selectedUser);
            bool moneySent = false;

            do
            {
                Console.Write("Enter the amount to send: ");
                string moneyToSend = Console.ReadLine().Trim();
                try
                {
                    decimal convertedMoneyToSend = Convert.ToDecimal(moneyToSend);
                    if (convertedMoneyToSend < 0 || convertedMoneyToSend == 0)
                    {
                        Console.WriteLine("Please enter a postive number");
                    }
                    else
                    {
                        if (convertedMoneyToSend > accountService.GetBalance(UserService.GetUserId()))
                        {
                            Console.WriteLine("Sorry, you don't have enough funds.");
                        }
                        else
                        {
                            Transfer transfer = new Transfer(2, 2, UserService.GetUserId(), Convert.ToInt32(sendToUser), convertedMoneyToSend);
                            if (transferService.SendMoney(transfer))
                            {
                                Console.WriteLine("Successfully sent, thank you for using TEnmo!");
                                Console.WriteLine("Please press enter to return");
                                Console.ReadLine();
                                moneySent = true;
                                Console.Clear();
                                return;
                            }
                            else
                            {
                                Console.WriteLine("Something went wrong, please press enter to try again");
                                Console.ReadLine();
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry, that's not a valid entry, please press enter to try again");
                    Console.ReadLine();
                }
            } while (!moneySent);
        }