public bool AddToCart(Product product, ShoppingCart cart) { if(product != null && cart != null) { var cartItem = storeDB.Carts.SingleOrDefault( c => c.CartId == cart.ShopCartId && c.ProductId == product.ProductId); if (cartItem == null) { cartItem = new Cart { ProductId = product.ProductId, CartId = cart.ShopCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { cartItem.Count++; } storeDB.SaveChanges(); return true; } else { return false; } }
public List<Cart> GetCartItems(ShoppingCart cart) { if(cart != null) { var list = new List<Cart>(); var ca = new Cart() { CartId = "1", Count = 1, DateCreated = DateTime.Now, RecordId = 1 }; list.Add(ca); return list; } else { return null; } }