Example #1
0
        public void StartCashDispenserProcess()
        {
            bool _doTransaction = true;

            while (_doTransaction == true)
            {
                CashDispenserView     _view                    = new CashDispenserView();
                IUserRepository       _userRepo                = new InFileUserRepository();
                CashDispenserProvider _cashProvider            = new CashDispenserProvider();
                CashDispenserProviderCommandResponse _response = new CashDispenserProviderCommandResponse(new bool(), new Dictionary <int, int>());


                int cardNumber = _view.GetUserCardNumber();
                if (_userRepo.CheckUserCardNumber(cardNumber))
                {
                    int pinNumber = _view.GetCardPinNumber();
                    if (_userRepo.CheckCardPinNumber(cardNumber, pinNumber))
                    {
                        int moneyAmount = _view.GetMoneyAmount();
                        if (_userRepo.CheckUserMoneyBalance(cardNumber, moneyAmount))
                        {
                            _response = _cashProvider.CalculateMoney(moneyAmount);
                            if (_response.IsBalanceOK == true)
                            {
                                _cashProvider.DepleteBanknotes(_response);
                                _userRepo.DepleteUserMoneyBalance(cardNumber, moneyAmount);
                                _view.TransactionSuccessful();
                            }
                            else
                            {
                                _view.WrongAmount();
                            }
                        }
                        else
                        {
                            _view.WrongAmount();
                        }
                    }
                }
                _doTransaction = _view.NextTransaction();
            }
        }
        public bool DepleteBanknotes(CashDispenserProviderCommandResponse banknotes)
        {
            bool _response = true;
            int _numberOfBanknotesTypes = banknotes.BanknotesToWithdraw.Count();
            int _banknoteValue = banknotes.BanknotesToWithdraw.Keys.Max();

            if (banknotes.IsBalanceOK == true)
            {
                for (int i = 0; i < _numberOfBanknotesTypes; i++)
                {
                    _banknoteValue = banknotes.BanknotesToWithdraw.Keys.Max();
                    while ((banknotes.BanknotesToWithdraw[_banknoteValue] > 0) && (_response == true))
                    {
                        _response=_cashRepo.DepleteBanknoteIfAvailable(_banknoteValue);
                        if (_response == true) banknotes.BanknotesToWithdraw[_banknoteValue] -= 1;
                    }
                    banknotes.BanknotesToWithdraw.Remove(_banknoteValue);
                   
                }
                _cashRepo.DepleteBanknoteIfAvailable(_banknoteValue);
            }
            return _response;
        }