Beispiel #1
0
        public bool Withdraw(IReadOnlyCashTransaction cashTransaction)
        {
            bool isValid = true;

            foreach (var key in _billInventory.Keys)
            {
                isValid = isValid && (_billInventory[key] >= cashTransaction.BillCount(key));
                if (isValid == false)
                {
                    break;
                }
            }
            // Only set the inventory if the withdraw can happen.
            if (isValid == true)
            {
                foreach (var bill in UnitedStatesTender.GetAllDefinedTenders())
                {
                    if (_billInventory.ContainsKey(bill))
                    {
                        _billInventory[bill] = _billInventory[bill] - cashTransaction.BillCount(bill);
                    }
                }
            }
            return(isValid);
        }
Beispiel #2
0
 public void ResetInventory(IReadOnlyCashTransaction restock)
 {
     foreach (var key in UnitedStatesTender.GetAllDefinedTenders())
     {
         if (_billInventory.ContainsKey(key))
         {
             _billInventory[key] = restock.BillCount(key);
         }
     }
 }
Beispiel #3
0
        public AtmInventory()
        {
            _billInventory = new Dictionary <UnitedStatesTender, int>();
            var allTenders = UnitedStatesTender.GetAllDefinedTenders();

            foreach (var tender in allTenders)
            {
                _billInventory.Add(tender, 0);
            }
        }