public void RemoveCartItem(Customer customer, Book book, int quantity) { var db_cartItem_rm = new Entities.CartitemEntity { ItemId = customer.MyCart.CartItems.First((b) => b.Book.ISBN == book.ISBN).ID }; var db_location = _context.Inventories.First(i => i.LocationId == customer.MyStoreLocation.ID); db_location.Quantity += quantity; _context.Set <Entities.CartitemEntity>().Remove(db_cartItem_rm); _context.SaveChanges(); }
public void AddCartItem(Customer customer, Book book, int quantity) { var db_cartItem = new Entities.CartitemEntity { BookIsbn = book.ISBN, Quantity = quantity, ShoppingcartId = customer.MyCart.ID }; // Add the new entity to the context to send over to the database _context.Add(db_cartItem); // I am using the aproach of sending the data over after each change instead of having a universal save button _context.SaveChanges(); }