Exemplo n.º 1
0
        public void UpdateItem(ProductViewDetailModel sp, int quantity)
        {
            CartItem line = lineCollection
                            .Where(p => p.Sanpham.maSanPham == sp.maSanPham)
                            .FirstOrDefault();

            if (line != null)
            {
                if (quantity > 0)
                {
                    line.Quantity = quantity;
                }
                else
                {
                    lineCollection.RemoveAll(l => l.Sanpham.maSanPham == sp.maSanPham);
                }
            }
        }
Exemplo n.º 2
0
        public void AddItem(ProductViewDetailModel sp, int quantity)
        {
            CartItem line = lineCollection
                            .Where(p => p.Sanpham.maSanPham == sp.maSanPham)
                            .FirstOrDefault();

            if (line == null)
            {
                lineCollection.Add(new CartItem
                {
                    Sanpham  = sp,
                    Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
                if (line.Quantity <= 0)
                {
                    lineCollection.RemoveAll(l => l.Sanpham.maSanPham == sp.maSanPham);
                }
            }
        }