public void AddItem(Product product, int quantity) { Console.WriteLine("Add Item =" + product.ProductID + " q=" + quantity); CarteLine line = lineCollection.Where(p => p.ProductID == product.ProductID).FirstOrDefault(); CarteLine2 line2 = lineCollection2.FirstOrDefault(pp2 => pp2.product.ProductID == product.ProductID); if (line == null) { lineCollection.Add(new CarteLine { ProductID = product.ProductID, Quantity = quantity }); } else { line.Quantity += quantity; } if (line2 == null) { Console.WriteLine("Add Item =" + product.ProductID + " q=" + quantity); lineCollection2.Add(new CarteLine2 { product = prodList.First(ps => ps.ProductID == product.ProductID), Quantity = quantity }); } else { line2.Quantity += quantity; } }
public void AddItem(Product product, int quantity) { CarteLine line = lineCollection.Where(p => p.Product.ProductID == product.ProductID).FirstOrDefault(); if (line == null) { lineCollection.Add(new CarteLine { Product = product, Quantity = quantity }); } else { line.Quantity += quantity; } }