public void PerformThirdPartyTransfer(BankAccount bankAccount, VMThirdPartyTransfer vMThirdPartyTransfer) { if (vMThirdPartyTransfer.TransferAmount <= 0) { Utility.PrintMessage("Amount needs to be more than zero. Try again.", false); } else if (vMThirdPartyTransfer.TransferAmount > bankAccount.Balance) { // Check giver's account balance - Start Utility.PrintMessage($"Withdrawal failed. You do not have enough fund to withdraw {Utility.FormatAmount(transaction_amt)}", false); } else if (bankAccount.Balance - vMThirdPartyTransfer.TransferAmount < 20) { Utility.PrintMessage($"Withdrawal failed. Your account needs to have minimum {Utility.FormatAmount(minimum_kept_amt)}", false); } // Check giver's account balance - End else { // Check if receiver's bank account number is valid. var selectedBankAccountReceiver = (from b in _accountList where b.AccountNumber == vMThirdPartyTransfer.RecipientBankAccountNumber select b).FirstOrDefault(); if (selectedBankAccountReceiver == null) { Utility.PrintMessage($"Third party transfer failed. Receiver bank account number is invalid.", false); } else if (selectedBankAccountReceiver.FullName != vMThirdPartyTransfer.RecipientBankAccountName) { Utility.PrintMessage($"Third party transfer failed. Recipient's account name does not match.", false); } else { // Bind transaction_amt to Transaction object // Add transaction record - Start Transaction transaction = new Transaction() { BankAccountNoFrom = bankAccount.AccountNumber, BankAccountNoTo = vMThirdPartyTransfer.RecipientBankAccountNumber, TransactionType = TransactionType.ThirdPartyTransfer, TransactionAmount = vMThirdPartyTransfer.TransferAmount, TransactionDate = DateTime.Now }; _listOfTransactions.Add(transaction); Utility.PrintMessage($"You have successfully transferred out {Utility.FormatAmount(vMThirdPartyTransfer.TransferAmount)} to {vMThirdPartyTransfer.RecipientBankAccountName}", true); // Add transaction record - End // Update balance amount (Giver) bankAccount.Balance = bankAccount.Balance - vMThirdPartyTransfer.TransferAmount; // Update balance amount (Receiver) selectedBankAccountReceiver.Balance = selectedBankAccountReceiver.Balance + vMThirdPartyTransfer.TransferAmount; } } }
public static VMThirdPartyTransfer ThirdPartyTransferForm() { var vMThirdPartyTransfer = new VMThirdPartyTransfer(); vMThirdPartyTransfer.RecipientBankAccountNumber = Utility.GetValidIntInputAmt("recipient's account number"); //Console.Write($"\nTransfer amount: {cur}"); vMThirdPartyTransfer.TransferAmount = Utility.GetValidDecimalInputAmt("amount"); //Console.Write("\nRecipient's account name: "); vMThirdPartyTransfer.RecipientBankAccountName = Utility.GetRawInput("recipient's account name"); // no validation here yet. return(vMThirdPartyTransfer); }
public void Execute() { //Initialization(); ATMScreen.ShowMenu1(); while (true) { switch (Utility.GetValidIntInputAmt("your option")) { case 1: CheckCardNoPassword(); _listOfTransactions = new List <Transaction>(); while (true) { ATMScreen.ShowMenu2(); switch (Utility.GetValidIntInputAmt("your option")) { case (int)SecureMenu.CheckBalance: CheckBalance(selectedAccount); break; case (int)SecureMenu.PlaceDeposit: PlaceDeposit(selectedAccount); break; case (int)SecureMenu.MakeWithdrawal: MakeWithdrawal(selectedAccount); break; case (int)SecureMenu.ThirdPartyTransfer: var vMThirdPartyTransfer = new VMThirdPartyTransfer(); vMThirdPartyTransfer = ATMScreen.ThirdPartyTransferForm(); PerformThirdPartyTransfer(selectedAccount, vMThirdPartyTransfer); break; case (int)SecureMenu.ViewTransaction: ViewTransaction(selectedAccount); break; case (int)SecureMenu.Logout: Utility.PrintMessage("You have succesfully logout. Please collect your ATM card..", true); Execute(); break; default: Utility.PrintMessage("Invalid Option Entered.", false); break; } } case 2: Console.Write("\nThank you for using Meybank. Exiting program now ."); Utility.printDotAnimation(15); System.Environment.Exit(1); break; default: Utility.PrintMessage("Invalid Option Entered.", false); break; } } }