/// <summary> /// Adds item to shopping cart and redirect to shopping cart page. /// </summary> protected void ButtonAddToCart_Click(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } // Retrieve product via Product Facade. var repository = new ProductRepository(); ActionServiceReference.Product product = repository.GetProduct(ProductId); // Get product details and add information to cart. int productId = product.ProductId; string name = product.ProductName; double unitPrice = product.UnitPrice; int quantity; if (!int.TryParse(TextBoxQuantity.Text.Trim(), out quantity)) { quantity = 1; } var cartRepository = new CartRepository(); cartRepository.AddItem(productId, name, quantity, unitPrice); // Show shopping cart to user. Response.Redirect(UrlMaker.ToCart()); }