示例#1
0
        // Add garment to cart
        public void AddToCart(Garment garment)
        {
            //Check if garment exists in cart
            var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.GarmentId == garment.GarmentID);

            if (cartItem == null)
            {
                //No garment in cart create new and add
                Cart cart = new Cart
                {
                    CartId      = ShoppingCartId,
                    GarmentId   = garment.GarmentID,
                    DateCreated = System.DateTime.Now,
                    Count       = 1
                };
                storeDB.Carts.Add(cart);
            }
            else
            {
                //Garment in cart increase count
                cartItem.Count++;
            }
            storeDB.SaveChanges();
        }
示例#2
0
        // Add garment to cart
        public void AddToCart(Garment garment)
        {
            //Check if garment exists in cart
            var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.GarmentId == garment.GarmentID);

            if (cartItem == null)
            {
                //No garment in cart create new and add
                Cart cart = new Cart
                {
                    CartId = ShoppingCartId,
                    GarmentId = garment.GarmentID,
                    DateCreated = System.DateTime.Now,
                    Count = 1
                };
                storeDB.Carts.Add(cart);
            }
            else
            {
                //Garment in cart increase count
                cartItem.Count++;
            }
            storeDB.SaveChanges();
        }