Пример #1
0
        /// <summary>
        /// This function is required for implementing the IPageExtender interface and will
        /// be called in order to verify that the requested Url is a part of the extended
        /// page or not.
        /// </summary>
        /// <param name="pageId">The id of the page being extended</param>
        /// <param name="remainingSegments">The remaining Url segments from the page and on</param>
        /// <returns></returns>
        public bool HandleRequest(Guid pageId, string[] remainingSegments)
        {
            // We only handle one level of additional paths in this extender
            if (remainingSegments.Length != 1)
            {
                return(false);
            }

            // Check if this was a called for a valid product in our product database
            if (FakeProductDatabase.IsValidProduct(remainingSegments[0]))
            {
                // It was, so lets execute the Product action in our page controller
                // (ProductListPageController). The product list page will be passed
                // to the action by default, but we also need to attach the product id.
                // This is done by adding it to a dictionary of route values.
                var page = PageFactory.GetPage(pageId);
                var additionalRouteData = new Dictionary <string, object> {
                    { "productId", remainingSegments[0] }
                };

                RouteUtils.RedirectToController(page, "product", additionalRouteData);

                return(true);
            }

            // Tell the request handler that the requested Url is unknown
            return(false);
        }
Пример #2
0
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            ProductList.DataSource = FakeProductDatabase.GetProducts();
            ProductList.DataBind();
        }
Пример #3
0
        public static ProductListPageViewModel Create(ProductListPage currentPage)
        {
            var model = new ProductListPageViewModel(currentPage);

            PageViewModelBuilder.SetBaseProperties(model);
            model.Products = FakeProductDatabase.GetProducts();
            return(model);
        }
Пример #4
0
        public ActionResult Product(ProductListPage currentPage, string productId)
        {
            var model = ProductListPageViewModelBuilder.Create(currentPage);

            // Get the product from our fake product store
            model.SelectedProduct = FakeProductDatabase.GetProduct(productId);

            return(View("Product", model));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Our IPageExtender should have attached a productid
            var productId = Request.QueryString["productid"];

            // Get the product from our fake product store
            var product = FakeProductDatabase.GetProduct(productId);

            // Lets populate the controls with out product data
            Heading.Text     = product.Name;
            Description.Text = product.Description;

            // Get all the products and bind it to our menu repeater
            ProductList.DataSource = FakeProductDatabase.GetProducts();
            ProductList.DataBind();
        }
        /// <summary>
        /// This function is required for implementing the IPageExtender interface and will
        /// be called in order to verify that the requested Url is a part of the extended
        /// page or not.
        /// </summary>
        /// <param name="pageId">The id of the page being extended</param>
        /// <param name="remainingSegments">The remaining Url segments from the page and on</param>
        /// <returns></returns>
        public bool HandleRequest(Guid pageId, string[] remainingSegments)
        {
            // We only handle one level of additional paths in this extender
            if (remainingSegments.Length != 1)
            {
                return(false);
            }

            // Check if this was a called for a valid product in our product database
            if (FakeProductDatabase.IsValidProduct(remainingSegments[0]))
            {
                // It was, so lets execute ProductPage.aspx. By attaching the pageId
                // as id in the querystring and letting ProductPage inherit from
                // PageTemplate we can access all properties from the "mother page".
                HttpContext.Current.RewritePath(string.Format("~/Templates/Pages/ProductPage.aspx?id={0}&productid={1}", pageId, remainingSegments[0]));
                return(true);
            }

            // Tell the request handler that the requested Url is unknown
            return(false);
        }