Beispiel #1
0
        public ActionResult CategorySEF(string relativeUrl, int pageNumber = 1, int pageSize = 10)
        {
            try
            {
                string pageUrl = relativeUrl.Split('/').Last();
                bool   exists  = _newsCategoryService.CategoryExists(pageUrl);
                if (!exists)
                {
                    throw new HttpException(404, "Not found");
                }

                var category = _newsCategoryService.GetCategory(pageUrl);

                if (category.CanonicalUrl != relativeUrl)
                {
                    return(RedirectPermanent(Url.RouteUrl("BlogModuleSEF", new { relativeUrl = category.CanonicalUrl })));
                }
                ViewBag.CategoryName = category.Name;
                if (category.ChildrenCategories.Any())
                {
                    return(View("Subcategories", category));
                }
                else
                {
                    int totalCount;
                    IEnumerable <NewsItem> news =
                        _newsItemService.GetNewsPage(new NewsFilter()
                    {
                        CategoryQuery = category.CategoryId.ToString()
                    },
                                                     pageNumber, pageSize, out totalCount);
                    ViewBag.TotalCount  = totalCount;
                    ViewBag.NoLayout    = false;
                    ViewBag.PagingRoute = "CategorySEF";



                    return(View("Page", news));
                }
            }
            catch (Exception)
            {
                throw new HttpException(404, "Not found");
            }
        }