Ejemplo n.º 1
0
        public void Add(string sku)
        {
            var product = productRepository.GetBySku(sku);

            if (product == null)
            {
                return;
            }

            // if product is first of its type in the shopping list, refresh the ProductDiscounts to include any for this new product
            // currently brings all, neeeds to pass array of distinct SKU's so as not to include discounts that are not needed
            if (!shoppingList.Any(x => x.Product.SKU == sku))
            {
                productDiscounts = productDiscountRepository.GetBySkus();
            }

            var id = 1;

            if (shoppingList.Count > 0)
            {
                id = shoppingList.Max(x => x.Id) + 1;
            }

            shoppingList.Add(new ShoppingListItem
            {
                Id      = id,
                Product = product
            });

            ApplyDiscounts();
        }