Пример #1
0
        public void Transfer(int accountNo)
        {
            //create variables for values to get user input in
            string recAccountNo      = default;
            int    recieverAccountNo = default;
            int    accountNoRe       = default;
            int    amount            = default;

            bool transferred = false;

            Console.Write("Enter amount in multiples of 500 : ");
            try
            {
                amount = System.Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if (amount % 500 != 0)
            {
                Console.WriteLine("Please make sure to enter the amount in MULTIPLES OF 500!");
            }
            else
            {
                Console.Write("Enter the account number to which you want to transfer : ");
                try
                {
                    recAccountNo      = Console.ReadLine();
                    recieverAccountNo = System.Convert.ToInt32(recAccountNo);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //create a list to hold customer business objects
                List <Customer_BO> found = new List <Customer_BO>();
                //create a list to hold arguments to pass to search function
                List <string> list = new List <string>();
                //add only accountnumber so it can search based on only that
                list.Add("AccountNumber");
                Admin_BLL adminBLL = new Admin_BLL();
                found = adminBLL.SearchAccount(recAccountNo, "", "", "", "", "", list);
                if (found.Count != 0)
                {
                    Customer_BO recieverObj = found.First();
                    Console.Write($"You wish to deposit Rs {amount} in account held by Mr. {recieverObj.Name} ; If this information is correct then please re-enter the account number: ");
                    try
                    {
                        accountNoRe = System.Convert.ToInt32(Console.ReadLine());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    if (recieverAccountNo == accountNoRe)
                    {
                        //call transaction function
                        transferred = cBLL.Transfer(accountNo, recieverAccountNo, amount);
                    }
                    if (transferred)
                    {
                        Console.WriteLine("Transaction confirmed");

                        Console.Write("do you wish to print a receipt (Y/N) ? : ");
                        string confirm = Console.ReadLine();
                        if (confirm == "Y")
                        {
                            List <Customer_BO> senderlist = new List <Customer_BO>();
                            List <string>      listTemp   = new List <string>();
                            listTemp.Add("AccountNumber");

                            senderlist = adminBLL.SearchAccount(accountNo.ToString(), "", "", "", "", "", listTemp);
                            Customer_BO sender = senderlist.First();

                            Console.WriteLine("\n");

                            //Display account number
                            Console.Write($"Account # {sender.AccountNumber}");
                            string date = sender.datetime.ToString("dd/MM/yyyy");
                            Console.WriteLine("\n");
                            Console.Write(date);
                            Console.WriteLine("\n");
                            Console.WriteLine($"Depostited : {amount }");
                            Console.Write($"Balance : {sender.Balance}\n");
                            //Display Deposited amount:amount
                            //Display balance
                        }
                        else if (confirm == "N")
                        {
                            Console.WriteLine("Receipt will not be printed!");
                        }
                        else
                        {
                            Console.WriteLine("No valid option chosen");
                        }
                    }


                    else if (transferred == false)
                    {
                        Console.WriteLine("Transfer failed");
                    }
                }
                else
                {
                    Console.WriteLine("No record found");
                }
            }
            //return to main menu
            MainMenu(accountNo);
        }