Example #1
0
        static void AccountHolderServices(string accountId, Bank bank)
        {
            int     choice;
            Account account = bankManager.FindAccount(accountId, bank);

            do
            {
                Console.WriteLine("Please select your choice\n" +
                                  "1.Deposit Amount\n" +
                                  "2.Withdraw Amount\n" +
                                  "3.Transfer Amount\n" +
                                  "4.View Transactions\n" +
                                  "5.View Balance\n" +
                                  "6.Go Back");
                choice = Reader.ReadInt(1, 6);
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Please select the currency in which you want to deposit the amount");
                    for (int i = 0; i < bank.Currencies.Count; i++)
                    {
                        Console.WriteLine(i + 1 + " " + bank.Currencies[i].Name);
                    }
                    int index = Reader.ReadInt(1, bank.Currencies.Count);
                    Console.WriteLine("Please enter the amount");
                    float amount = Reader.ReadInt();
                    accountManager.Deposit(amount, bank.Currencies[index - 1], account);
                    Console.WriteLine("The Available Balance is" + account.Balance);
                    break;

                case 2:
                    Console.WriteLine("Please enter the amount");
                    float withdrawAmount = Reader.ReadInt();
                    if (accountManager.Withdraw(withdrawAmount, account))
                    {
                        Console.WriteLine("The Available Balance is" + account.Balance);
                    }
                    else
                    {
                        Console.WriteLine("Sorry,The Balance is not Sufficient");
                    }
                    break;

                case 3:
                    Console.WriteLine("Please enter the bank id of receiver");
                    string receiverBankId = Reader.ReadString();
                    Console.WriteLine("Please enter the account id of receiver");
                    string receiverAccountId = Reader.ReadString();
                    Console.WriteLine("Please enter the amount to transfer");
                    float   transferAmount = Reader.ReadFloat();
                    Account receiverAccount;
                    if (account.bankId == receiverBankId)
                    {
                        if (receiverAccountId == account.Id)
                        {
                            Console.WriteLine("Sorry,You can't transfer money to your account");
                        }
                        else
                        {
                            receiverAccount = bankManager.FindAccount(receiverAccountId, bank);
                            if (receiverAccount == null)
                            {
                                Console.WriteLine("The account with given id doesn't exist");
                            }
                            else
                            {
                                float charges = bankManager.GetCharges(bank, transferAmount, true);
                                accountManager.SendMoney(account, transferAmount, charges, receiverBankId, receiverAccountId);
                                accountManager.ReceiveMoney(receiverAccount, transferAmount, charges, account.bankId, account.Id);
                            }
                        }
                    }
                    else
                    {
                        float charges = bankManager.GetCharges(bank, transferAmount, false);
                        accountManager.SendMoney(account, transferAmount, charges, receiverBankId, receiverAccountId);
                    }
                    break;

                case 4:
                    ViewTransactions(account, false);
                    break;

                case 5:
                    float balance = accountManager.ViewBalance(account);
                    Console.WriteLine("The available balance is " + balance);
                    break;

                case 6:
                    break;
                }
            } while (choice != 6);
        }