Esempio n. 1
0
        public DiscountRuleBuilder WithUnits(StockKeepingUnit unit, int quantity)
        {
            ItemPile existinPile = _itemPiles.FirstOrDefault(i => i.Unit == unit);

            if (existinPile != null)
            {
                existinPile.AddToPile(quantity);
            }
            else
            {
                _itemPiles.Add(new ItemPile(unit, quantity));
            }

            return(this);
        }
Esempio n. 2
0
        public void Scan(string item)
        {
            if (string.IsNullOrWhiteSpace(item))
            {
                throw new ArgumentNullException(nameof(item)); //if this was a web api controller it should return a Bad Request
            }
            StockKeepingUnit unit = _unitRepository.GetByName(item);

            if (unit == null)
            {
                throw new Exception($"Item {item} does not exist in stock.");
            }

            ItemPile existingPile = _basket.FirstOrDefault(p => p.Unit == unit);

            if (existingPile != null)
            {
                existingPile.AddToPile(1);
            }
            else
            {
                _basket.Add(new ItemPile(unit, 1));
            }
        }