public void Remove(Audiobook audiobook) { var cartItem = db.Carts.Single( c => c.Cart_Id == ShoppingCartId && c.Item_Id == audiobook.Id); if (cartItem != null) { db.Carts.Remove(cartItem); } db.SaveChanges(); }
public void Add(Audiobook audiobook) { // Get items in the cart var cartItem = db.Carts.SingleOrDefault( c => c.Cart_Id == ShoppingCartId && c.Item_Id == audiobook.Id); if (cartItem == null) { // Create a new item if no item exist in the cart. cartItem = new Cart { Item_Id = audiobook.Id, Cart_Id = ShoppingCartId }; db.Carts.Add(cartItem); } db.SaveChanges(); }