public void UpdateItem(THUOC sp, int quantity) { CartItem line = lineCollection.Where(p => p.Thuoc.MaThuoc == sp.MaThuoc).FirstOrDefault(); if (line != null) { if (quantity > 0) { line.Quantity = quantity; } else { lineCollection.RemoveAll(l => l.Thuoc.MaThuoc == sp.MaThuoc); } } }
public void AddItem(THUOC sp) { CartItem line = lineCollection.Where(p => p.Thuoc.MaThuoc == sp.MaThuoc).FirstOrDefault(); if (line == null) { lineCollection.Add(new CartItem { Thuoc = sp, Quantity = 1 }); } else { line.Quantity += 1; if (line.Quantity <= 0) { lineCollection.RemoveAll(l => l.Thuoc.MaThuoc == sp.MaThuoc); } } }
public void RemoveLine(THUOC sp) { lineCollection.RemoveAll(l => l.Thuoc.MaThuoc == sp.MaThuoc); }