Exemplo n.º 1
0
        public async Task <IActionResult> PostListByCategory(string categoryName, int?categoryId, int page = 1)
        {
            if (categoryId.HasValue)
            {
                var query    = postService.GetAllPostByCategoryIdDescendingQuery(categoryId.Value);
                var postList = await PagingList.CreateAsync(query, 5, page);

                var category = await categoryService.GetCategoryByIdAsync(categoryId.Value);

                // paging configuration
                postList.Action     = "PostListByCategory";
                postList.RouteValue = new RouteValueDictionary(new { categoryId = categoryId });

                PostListByCategoryViewModel model = new PostListByCategoryViewModel
                {
                    PostList = postList,
                    Category = category
                };

                return(View(model));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 2
0
        public IActionResult Index(string url, int?pageSize, string sortBy, int trang = 1)
        {
            var catalog = new PostListByCategoryViewModel();

            if (pageSize == null)
            {
                pageSize = _configuration.GetValue <int>("PageSize");
            }

            //pageSize = 10;
            catalog.PageSize = pageSize;
            catalog.SortType = sortBy;

            var category   = _postCategoryService.GetByUrl(url);
            var categoryId = category.Id;

            //ViewBag.CategoryName = category.Name;
            //ViewBag.MetaTitle = category.MetaTitle;
            //ViewBag.MetaDescription = category.MetaDescription;
            //ViewBag.MetaKeywords = category.MetaKeywords;
            //ViewBag.Url = category.Url;
            //var list = _postService.GetAllByCategoryId(categoryId);

            catalog.Data     = _postService.GetAllPaging(categoryId, string.Empty, trang, pageSize.Value);
            catalog.Category = category;
            return(View(catalog));
        }