public void AddItem(Product product, int quantity) { CartLine line = lineCollection .FirstOrDefault(p => p.Product.ProductID == product.ProductID); if (line == null) { lineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } else { line.Quantity += quantity; } }
public void SaveProduct(Product product) { if (product.ProductID == 0) context.Product.Add(product); else { Product dbEntry = context.Product.Find(product.ProductID); if (dbEntry != null) { dbEntry.Name = product.Name; dbEntry.Author = product.Author; dbEntry.Category = product.Category; dbEntry.Description = product.Description; dbEntry.Price = product.Price; } } context.SaveChanges(); }
public void RemoveLine(Product product) { lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID); }