示例#1
0
        private void AddToCart()
        {
            int quantity = int.Parse(Quantity);

            // If true, update quantity on the item already in the cart
            if (ShoppingCartHelper.IsAlreadyInCart(Product, SelectedSize.Size))
            {
                ShoppingCartHelper.UpdateItemQuantity(Product.ProductId, SelectedSize.Size, quantity);
                return;
            }

            var productVM = new ProductViewModel
            {
                ProductId   = Product.ProductId,
                Name        = Product.Name,
                Description = Product.Description,
                ImageUrl    = Product.ImageUrl,
                Quantity    = quantity,
                Size        = SelectedSize.Size,
                Cost        = SelectedSize.Cost * quantity
            };

            ShoppingCartHelper.AddToCart(productVM);
        }