Esempio n. 1
0
 /// <summary>
 /// 从购物车中移除一个商品
 /// </summary>
 /// <param name="sku">货品编号(唯一) </param>
 /// <returns>返回移除</returns>
 public void Remove(string sku)
 {
     lock (_sync)
     {
         if (CartItems != null)
         {
             CartItems.RemoveAll(p => sku != null && p.SKU == sku);
         }
     }
 }
Esempio n. 2
0
        public int RemoveProduct(IProduct product, int amount = 1)
        {
            if (!CartProductIds.Contains(product.GetId()))
            {
                throw new InvalidOperationException("No such product in a cart");
            }

            ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product));

            if (item == null)
            {
                throw new InvalidOperationException("Item exist in HashSet but not in CartItems");
            }

            if (item.GetAmount() != amount)
            {
                return(item.DecreaseAmountOn(amount));
            }

            // here item should be deleted
            CartProductIds.Remove(product.GetId());
            CartItems.RemoveAll(cartItem => cartItem.GetProduct().Equals(product));
            return(0);
        }
Esempio n. 3
0
 public void ClearCart()
 {
     CartItems.RemoveAll(r => r.isProduct == true);
     CartItems.RemoveAll(r => r.isProduct == false);
 }