예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            int productId = Convert.ToInt32(context.Request["pid"]);
            AdventureWorksRepository repository = new AdventureWorksRepository();
            byte[] imageData = repository.GetProductImage(productId);

            context.Response.ContentType = "Image/gif";
            context.Response.OutputStream.Write(imageData, 0, imageData.Length);
        }
예제 #2
0
        protected void AddToCartLinkButton_Click(object sender, EventArgs e)
        {
            LinkButton cartLinkButton = sender as LinkButton;
            int productId = (cartLinkButton != null) ? Convert.ToInt32(cartLinkButton.CommandArgument) : 1;
            AdventureWorksRepository repository = new AdventureWorksRepository();
            Product product = repository.GetProduct(productId);

            if (product != null)
            {
                ShoppingCart cart = ShoppingCartFactory.GetInstance();
                cart.AddItem(product.ProductID, product.ProductNumber, product.ListPrice, 1);
            }
        }
예제 #3
0
        private string GetCategoryName()
        {
            string category = Request.QueryString["category"] as string;
            AdventureWorksRepository repository = new AdventureWorksRepository();

            if (category != null)
            {
                return category;
            }

            return repository.GetCategories()[0].Name;
        }
예제 #4
0
        private void ApplyProductsFilter()
        {
            AdventureWorksRepository repository = new AdventureWorksRepository();
            int[] subcatIds = (from c in repository.GetSubcategories(this.SelectedCategoryName)
                               select c.ProductCategoryID).ToArray();

            this.TotalPages = (int)(Math.Ceiling(((double)repository.GetProductsCountByCategories(subcatIds)) / ((double)pageSize)));
            Product[] products = repository.GetProductsByCategories(subcatIds, this.SelectedPage, (int)pageSize);

            ProductDataList.DataSource = products;
            ProductDataList.DataBind();

            ProductListPanel.Visible = true;
            PageIndexOverflowPanel.Visible = ((this.TotalPages < this.SelectedPage) && (this.TotalPages != 0));
            NoProductsFoundPanel.Visible = ((products.Length == 0) && (this.TotalPages == 0));
            PagerPanel.Visible = (this.TotalPages > 1);
        }
예제 #5
0
        private string GetCategoryName()
        {
            string category = RouteData.Values["category"] as string;
            AdventureWorksRepository repository = new AdventureWorksRepository();

            if (category != null)
            {
                return category;
            }

            return repository.GetCategories()[0].Name;
        }