Example #1
0
        public ActionResult SectionPosts(int id, string path, int page = 0)
        {
            if (page < 0)
            {
                throw new ArgumentException("Page less than 0");
            }

            bool isLastPage, isFirstPage;
            var  articles = _articleService.GetArticlesForPage(PageSize, page, out isLastPage, out isFirstPage,
                                                               x => x.PublishTime, isAscOrder: false, sectionId: id);

            if (articles == null)
            {
                return(new EmptyResult());
            }

            var posts = Mapper.Map <IEnumerable <Article>, IEnumerable <PostIndexVm> >(articles);

            var vm = new PostsListVm()
            {
                UrlNext   = string.Format("/{0}/{1}", path, page + 1),
                UrlBack   = string.Format("/{0}/{1}", path, page - 1),
                PostsList = posts, IsLastPage = isLastPage, IsFirstPage = isFirstPage
            };

            return(PartialView("_PostsList", vm));
        }
Example #2
0
        public ActionResult BestPosts(int page = 0)
        {
            if (page < 0)
            {
                throw new ArgumentException("Page less than 0");
            }

            bool isLastPage, isFirstPage;
            var  articles = _articleService.GetArticlesForPage(PageSize, page, out isLastPage, out isFirstPage, x => x.Rating);

            if (articles == null)
            {
                return(new EmptyResult());
            }

            var posts = Mapper.Map <IEnumerable <Article>, IEnumerable <PostIndexVm> >(articles);

            var vm = new PostsListVm()
            {
                UrlNext   = Url.Action("Best", "Home", new { page = page + 1 }),
                UrlBack   = Url.Action("Best", "Home", new { page = page - 1 }),
                PostsList = posts, IsLastPage = isLastPage, IsFirstPage = isFirstPage
            };

            return(PartialView("_PostsList", vm));
        }
Example #3
0
        public ActionResult Search(SearchVm searchVm)
        {
            if (searchVm.Page < 0)
            {
                throw new ArgumentException("Page less than 0");
            }

            bool isLastPage, isFirstPage;
            var  articles = _articleService.GetArticlesForPage(pageSize, searchVm.Page, out isLastPage,
                                                               out isFirstPage, x => x.Rating, _articleService.SearchArticles(searchVm.SearchText));

            if (articles == null)
            {
                return(new EmptyResult());
            }

            var posts = Mapper.Map <IEnumerable <Article>, IEnumerable <PostIndexVm> >(articles);

            SearchVm vmBack = new SearchVm()
            {
                Page = searchVm.Page - 1, SearchText = searchVm.SearchText
            };

            searchVm.Page += 1;

            var vm = new PostsListVm()
            {
                UrlNext   = Url.Action("Search", "Home", searchVm),
                UrlBack   = Url.Action("Search", "Home", vmBack),
                PostsList = posts, IsLastPage = isLastPage, IsFirstPage = isFirstPage
            };

            return(PartialView("../Post/_PostsList", vm));
        }