示例#1
0
        public void UpdateItem(SANPHAM sp, int quantity)
        {
            CartItem line = lineCollection.Where(p => p.Thuoc.MaSP == sp.MaSP).FirstOrDefault();

            if (line != null)
            {
                if (quantity > 0)
                {
                    line.Quantity  = quantity;
                    line.ThanhTien = (int)sp.GiaBan * quantity;
                }
                else
                {
                    lineCollection.RemoveAll(l => l.Thuoc.MaSP == sp.MaSP);
                }
            }
        }
示例#2
0
        public void AddItem(SANPHAM sp)
        {
            CartItem line = lineCollection.Where(p => p.Thuoc.MaSP == sp.MaSP).FirstOrDefault();

            if (line == null)
            {
                lineCollection.Add(new CartItem
                {
                    Thuoc    = sp,
                    Quantity = 1, ThanhTien = (int)sp.GiaBan
                });
            }
            else
            {
                line.Quantity += 1;
                line.ThanhTien = (int)sp.GiaBan * line.Quantity;
                if (line.Quantity <= 0)
                {
                    lineCollection.RemoveAll(l => l.Thuoc.MaSP == sp.MaSP);
                }
            }
        }
示例#3
0
 public void RemoveLine(SANPHAM sp)
 {
     lineCollection.RemoveAll(l => l.Thuoc.MaSP == sp.MaSP);
 }