Exemple #1
0
        /// <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.
            ProductController controller = new ProductController();
            ActionServiceReference.Product product = controller.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;

            CartController cartController = new CartController();
            cartController.AddItem(productId, name, quantity, unitPrice);

            // Show shopping cart to user.
            Response.Redirect("Cart.aspx");
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Initialize controller and cart
            _controller = new CartController();
            _shoppingCart = _controller.GetCart();

            if (!IsPostBack)
            {
                // Set the selected menu item in Master page.
                Master.TheMenuInMasterPage.SelectedItem = "cart";

                Bind();
            }
        }