public override void Execute()
        {
            bool    isCashDispensed = false;
            decimal availableBalance;

            IBankDatabase bankDatabase = base.BankDatabase;

            do
            {
                _amount = (decimal)DisplayMenuOfAmounts();

                if (_amount != CANCELED)
                {
                    availableBalance = bankDatabase.getAvailableBalance(AccountNumber);
                    if (_amount <= availableBalance)
                    {
                        if (_cashDispenser.IsSufficiantCashAvailable(_amount))
                        {
                            bankDatabase.Debit(AccountNumber, _amount);
                            _cashDispenser.DispenseCash(_amount);
                            isCashDispensed = true;

                            Screen.DisplayMessageLine("\nYour cash has been dispensed. Please take your cash now.");
                        }
                        else
                        {
                            Screen.DisplayMessageLine("\nInsufficient cash available in the ATM.\n\nPlease choose a smaller amount.");
                        }
                    }
                    else
                    {
                        Screen.DisplayMessage("\nInsufficient funds in your account.\n\nPlease choose a smaller amount.");
                    }
                    Sleep(3000);
                }
                else
                {
                    Screen.DisplayMessageLine("\nCancelling transaction...");
                    Sleep(3000);
                    return;
                }
            } while (!isCashDispensed);
        }
Exemple #2
0
 public void WithdrawCash(long cash)
 {
     _cashDispenser.CashDispensedSuccess += _display.DisplaySucess;
     _cashDispenser.CashDispensedFailed  += _display.DisplayError;
     _cashDispenser.DispenseCash(_withdrawAmount);
 }