Example #1
0
        // Method to do a Deposit
        public void CashDeposit(string username)
        {
            Data data = new Data();
            // Gets Customer object against given username
            Customer customer = new Customer();

            customer = data.GetCustomer(username);
getAmount:
            {
                Console.WriteLine("----- Deposit Cash -----\n");
                Console.Write("Enter amount to deposit: ");
                try
                {
                    int amount = Convert.ToInt32(Console.ReadLine());
                    // Add amount to the account
                    data.AddAmount(customer, amount);
                    Console.WriteLine("Cash Deposited Successfully.");

                    // Making and recording transaction to file for Sender
                    Transaction transaction = MakeTransaction(customer, amount, "Cash Deposit");

                    // Asking if user wants a receipt
                    Console.Write("Do you wish to print a receipt(Y/N)? ");
                    string y = Console.ReadLine();
                    if (y == "Y" || y == "y")
                    {
                        // printing receipt
                        PrintReceipt(transaction, "Amount Deposited");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Input. Try again!");
                    goto getAmount;
                }
            }
        }
Example #2
0
        // Method to Cash Transfer
        public void CashTransfer(string username)
        {
            Data data = new Data();
            // Gets Customer object against given username
            Customer sender = new Customer();

            sender = data.GetCustomer(username);
getAmount:
            {
                Console.WriteLine("----- Transfer Cash -----\n");
                Console.Write("Enter amount in multiples of 500: ");
                try
                {
                    // Reads amount in input
                    int amount = Convert.ToInt32(Console.ReadLine());
                    if (amount % 500 == 0)
                    {
                        if (amount <= sender.Balance)
                        {
getAccNo:
                            {
                                Console.Write("Enter the account number to which you want to transfer: ");
                                try
                                {
                                    int      accNo    = Convert.ToInt32(Console.ReadLine());
                                    Customer reciever = new Customer();
                                    if (data.isInFile(accNo, out reciever))
                                    {
                                        Console.Write($"You wish to deposit Rs. {amount} in account held by Mr. {reciever.Name}.\n" +
                                                      "If this information is correct please re-enter the account number: ");
                                        try
                                        {
                                            int accNo2 = Convert.ToInt32(Console.ReadLine());
                                            // checking if user entered the same account number both times
                                            if (accNo == accNo2)
                                            {
                                                // Deduct amount from Sender's account
                                                data.DeductBalance(sender, amount);

                                                // Add amount to receiver's account
                                                data.AddAmount(reciever, amount);

                                                Console.WriteLine("Transaction confirmed.");

                                                // Making and recording transaction to file for Sender
                                                Transaction transaction = MakeTransaction(sender, amount, "Cash Transfer");

                                                // Making and recording transaction to file for Receiver
                                                Transaction transaction1 = MakeTransaction(reciever, amount, "Cash Transfer");

                                                // Asking if user wants a receipt
                                                Console.Write("Do you wish to print a receipt(Y/N)? ");
                                                string y = Console.ReadLine();
                                                if (y == "Y" || y == "y")
                                                {
                                                    // printing receipt
                                                    PrintReceipt(transaction, "Amount Transfered");
                                                }
                                            }
                                            else
                                            {
                                                Console.WriteLine("Did not enter same account number. Trasaction Failed!");
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            Console.WriteLine("Did not enter same account number. Trasaction Failed!");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("Given Account does not exist!!");
                                    }
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine("Invalid Input. Try again!");
                                    goto getAccNo;
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Insufficent Balance!!!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input. Try again!");
                        goto getAmount;
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Input. Try again!");
                    goto getAmount;
                }
            }
        }