public void AddToCart(Car car) { // Get the matching cart and car instances /*var cartItem = catalogDB.Carts.SingleOrDefault( c => c.CartId == ShoppingCartId && c.CarId == car.CarId);*/ ShoppingCartDAL dal = new ShoppingCartDAL(); var cartItem = dal.MatchingCarAndCart(ShoppingCartId,car); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart { CarId = car.CarId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; /*catalogDB.Carts.Add(cartItem);*/ dal.AddCartItem(cartItem); } else { // If the item does exist in the cart, then add one to the quantity cartItem.Count++; } // Save changes /*catalogDB.SaveChanges();*/ dal.SaveChangestoCart(); }
public void RemoveCartItem(Cart cartItem) { catalogDB.Carts.Remove(cartItem); }
public void AddCartItem(Cart cartItem) { catalogDB.Carts.Add(cartItem); }