public void AddToCart(Product product)
        {
            // Get the matching cart and album instances
            var cart = GetCart(cartSessionID);
            var cartItem = cart.CartItems.SingleOrDefault(i => i.ProductID == product.ProductID);
            Debug.WriteLine("Add to cart: " + cartSessionID);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new CartItem
                {
                    ProductID = product.ProductID,
                    CartID = cart.ID,
                    Quantity = 1,
                };
                storeDB.CartItems.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Quantity += 1;
                Debug.WriteLine(cartItem.Quantity);
            }
            // Save changes
            Debug.WriteLine("Before : " + cartItem.Quantity);
            storeDB.SaveChanges();
            Debug.WriteLine("After " + cartItem.Quantity);
        }
        public CartItem AddToCart(CartItem cartItem)
        {
            var existingCartItem = GetByCartIdAndBookId(cartItem.CartId, cartItem.BookId);

            if (null == existingCartItem)
            {
                _db.Entry(cartItem).State = EntityState.Added;
                existingCartItem = cartItem;
            }
            else
            {
                existingCartItem.Quantity += cartItem.Quantity;
            }

            _db.SaveChanges();

            return existingCartItem;
        }
 public void DeleteCartItem(CartItem cartItem)
 {
     _db.Entry(cartItem).State = EntityState.Deleted;
     _db.SaveChanges();
 }
 public void UpdateCartItem(CartItem cartItem)
 {
     _db.Entry(cartItem).State = EntityState.Modified;
     _db.SaveChanges();
 }