public void Merge(AddToBasketViewModel item)
        {
            if (item.Id != Id) throw new InvalidOperationException();
            if (item.Description != Description) throw new InvalidOperationException();

            Quantity += item.Quantity;
        }
Exemplo n.º 2
0
        public void AddItem(AddToBasketViewModel item)
        {
            var existingItem = _items.SingleOrDefault(model => model.Id == item.Id);

            if (existingItem == null)
            {
                _items.Add(item);
                return;
            }

            existingItem.Merge(item);
        }
Exemplo n.º 3
0
        public void AddItem(AddToBasketViewModel item)
        {
            var existingItem = _items.SingleOrDefault(model => model.Id == item.Id);

            if (existingItem == null)
            {
                _items.Add(item);
                return;
            }

            existingItem.Merge(item);
        }
        public void Merge(AddToBasketViewModel item)
        {
            if (item.Id != Id)
            {
                throw new InvalidOperationException();
            }
            if (item.Description != Description)
            {
                throw new InvalidOperationException();
            }

            Quantity += item.Quantity;
        }
        public ActionResult AddToBasket(AddToBasketViewModel model)
        {
            var basket = HttpContext.Cache.Get("basket") as Basket;

            if (basket == null)
            {
                basket = new Basket();
                HttpContext.Cache.Add(
                    "basket",
                    basket,
                    null,
                    Cache.NoAbsoluteExpiration,
                    Cache.NoSlidingExpiration,
                    CacheItemPriority.Normal,
                    null);
            }

            basket.AddItem(model);

            return RedirectToAction("Index");
        }