/// <summary> /// Add an item to the cart. /// When ItemId to be added has already existed, this method will update the quantity instead. /// </summary> /// <param name="item">Item to add</param> public void Add(Model.CartItemInfo item) { Model.CartItemInfo cartItem; if (!cartItems.TryGetValue(item.ProductId, out cartItem)) { cartItems.Add(item.ProductId, item); } else { cartItem.Quantity += item.Quantity; } }
/// <summary> /// Add an item to the cart. /// When ItemId to be added has already existed, this method will update the quantity instead. /// </summary> /// <param name="itemId">Item Id of item to add</param> public void Add(string itemId) { Model.CartItemInfo cartItem; if (!cartItems.TryGetValue(itemId, out cartItem)) { BLL.Product pBll = new Product(); Model.Product model = pBll.GetModel(itemId); if (model != null) { Model.CartItemInfo newItem = new Model.CartItemInfo(itemId, model.ProductName, 1, model.ProductPrice, model.ImagesUrl); cartItems.Add(itemId, newItem); } } else { cartItem.Quantity++; } }