public bool addShoppingCartItem(int id, int quantity = 1) { var product = getProduct(id); if (product == null) { return false; } var productsInShoppingCart = getCurrentUsersShoppingCartItems(); var productInShoppingCart = productsInShoppingCart.Where(p => p.ProductID == product.ProductID); if (productInShoppingCart.Count() == 1) { productInShoppingCart.First().Quantity += quantity; } else { var item = new ShoppingCartItem(); item.ProductID = product.ProductID; item.Product = product; item.UserID = getCurrentUserId(); item.Quantity = quantity; db.ShoppingCartItems.Add(item); } db.SaveChanges(); return true; }
public void Add(ShoppingCartItem sh) { list.Add(sh); }