コード例 #1
0
        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();
        }
コード例 #2
0
 public void RemoveCartItem(Cart cartItem)
 {
     catalogDB.Carts.Remove(cartItem);
 }
コード例 #3
0
 public void AddCartItem(Cart cartItem)
 {
     catalogDB.Carts.Add(cartItem);
 }