// GET: ProductCategory

        public ActionResult Index(int id, int page = 1, string sort = "")
        {
            ProductCategory category = _productCategoryService.GetById(id);

            ViewBag.Category = Mapper.Map <ProductCategoryViewModel>(category);
            ViewBag.Sort     = sort;
            int pageSize = Common.CommonConstant.PageSize;
            int totalRow = 0;
            IEnumerable <Product>          listProductDb = _productService.GetAllByCategoryPaging(id, page, pageSize, sort, out totalRow);
            IEnumerable <ProductViewModel> listProductVm = Mapper.Map <IEnumerable <ProductViewModel> >(listProductDb);
            int totalPage = (int)Math.Ceiling((double)totalRow / pageSize);
            PaginationClient <ProductViewModel> pagination = new PaginationClient <ProductViewModel>()
            {
                TotalPage   = totalPage,
                TotalRows   = totalRow,
                PageDisplay = Common.CommonConstant.PageDisplay,
                Items       = listProductVm,
                PageIndex   = page,
                PageSize    = pageSize,
            };
            IEnumerable <Tag>          listTagProdut = _tagService.GetAll().Where(x => x.Type == Common.CommonConstant.ProductTag.ToString()).OrderByDescending(x => x.ID).Take(9);
            IEnumerable <TagViewModel> listTagVm     = Mapper.Map <IEnumerable <TagViewModel> >(listTagProdut);

            ViewBag.TagProduct = listTagVm;
            return(View(pagination));
        }
        public ActionResult Tag(string tagId, int page = 1)
        {
            int pageSize = Common.CommonConstant.PageSize;
            int totalRow = 0;
            IEnumerable <Product>          listProductDb = _productService.GetAllByTagPaging(tagId, page, pageSize, out totalRow);
            IEnumerable <ProductViewModel> listProductVm = Mapper.Map <IEnumerable <ProductViewModel> >(listProductDb);
            int totalPage = (int)Math.Ceiling((double)totalRow / pageSize);
            PaginationClient <ProductViewModel> pagination = new PaginationClient <ProductViewModel>()
            {
                PageIndex   = page,
                PageDisplay = Common.CommonConstant.PageDisplay,
                PageSize    = pageSize,
                TotalPage   = totalPage,
                TotalRows   = totalRow,
                Items       = listProductVm,
            };

            ViewBag.ProductTag = Mapper.Map <TagViewModel>(_tagService.GetDetail(tagId));
            return(View(pagination));
        }
Example #3
0
        // GET: Post
        public ActionResult Index(int id, int page = 1)
        {
            int pageSize = 2;
            int totalRow = 0;

            PostCategory          postCategoryDb = _postCategoryService.GetByID(id);
            PostCategoryViewModel postCategoryVm = Mapper.Map <PostCategoryViewModel>(postCategoryDb);

            ViewBag.Category = postCategoryVm;
            IEnumerable <Post>          listPostDb = _postService.GetByCategoryPaging(id, page, pageSize, out totalRow);
            IEnumerable <PostViewModel> listPostVm = Mapper.Map <IEnumerable <PostViewModel> >(listPostDb);
            int totalPage = (int)Math.Ceiling((double)totalRow / pageSize);
            PaginationClient <PostViewModel> pagination = new PaginationClient <PostViewModel>()
            {
                PageIndex   = page,
                PageDisplay = Common.CommonConstant.PageDisplay,
                PageSize    = pageSize,
                TotalPage   = totalPage,
                TotalRows   = totalRow,
                Items       = listPostVm,
            };

            return(View(pagination));
        }