예제 #1
0
        /// <summary>
        /// Sets datasources and bind data to controls.
        /// </summary>
        private void Bind()
        {
            // Validate selected CategoryId
            int categoryId;
            if (!int.TryParse(DropDownListCategories.SelectedValue, out categoryId))
                categoryId = 1;

            // Gets list of products.
            ProductController controller = new ProductController();
            GridViewProducts.DataSource = controller.GetProducts(categoryId, SortExpression);
            GridViewProducts.DataBind();
        }
예제 #2
0
        /// <summary>
        /// Takes search criteria, sets datasource, and bind data to controls.
        /// </summary>
        private void Bind()
        {
            // Validate price range.
            int priceRangeId;
            if (!int.TryParse(DropDownListRange.SelectedValue, out priceRangeId))
                priceRangeId = 0;

            // Get product name entered.
            string productName = this.TextBoxProductName.Text.Trim();

            // Retrieve list of products.
            ProductController controller = new ProductController();
            GridViewProducts.DataSource = controller.SearchProducts(productName, priceRangeId, SortExpression);
            GridViewProducts.DataBind();
        }
예제 #3
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");
        }