public IndexViewModel Index(IndexSetupViewModel inModel)
        {
            const int pageSizeToShow = 5;
            const int pageSizeToGet = 8;

            if (inModel.Page == 0)
                inModel.Page = 1;

            var posts = (inModel.Page == 1)
                ? _repository.Query<Post>().OrderByDescending(p => p.Published).Take(pageSizeToGet).ToList()
                : _repository.Query<Post>().OrderByDescending(p => p.Published).Skip(pageSizeToShow * (inModel.Page - 1)).Take(pageSizeToGet).ToList();

            bool showPreviousPageLink = !(inModel.Page == 1);
            bool showNextPageLink = posts.Count() == pageSizeToGet;
            var pageSize = showNextPageLink ? pageSizeToShow : pageSizeToGet;

            return new IndexViewModel
            {
                Posts = posts.ToList().Take(pageSize).Select(p => new PostDisplay(p)),
                SiteName = "{0} - Opinionated, let me tell you about it".ToFormat(inModel.SiteName),
                ShowNextPageLink = showNextPageLink,
                ShowPreviousPageLink = showPreviousPageLink,
                NextPage = inModel.Page + 1,
                PreviousPage = inModel.Page - 1,
                ShowBothLinks = showNextPageLink && showPreviousPageLink,
            };
        }
Exemple #2
0
        public IndexViewModel Index(IndexSetupViewModel inModel)
        {
            const int pageSizeToShow = 5;
            const int pageSizeToGet  = 8;

            if (inModel.Page == 0)
            {
                inModel.Page = 1;
            }

            var posts = (inModel.Page == 1)
                ? _repository.Query <Post>().OrderByDescending(p => p.Published).Take(pageSizeToGet).ToList()
                : _repository.Query <Post>().OrderByDescending(p => p.Published).Skip(pageSizeToShow * (inModel.Page - 1)).Take(pageSizeToGet).ToList();

            bool showPreviousPageLink = !(inModel.Page == 1);
            bool showNextPageLink     = posts.Count() == pageSizeToGet;
            var  pageSize             = showNextPageLink ? pageSizeToShow : pageSizeToGet;

            return(new IndexViewModel
            {
                Posts = posts.ToList().Take(pageSize).Select(p => new PostDisplay(p)),
                SiteName = "{0} - Opinionated, let me tell you about it".ToFormat(inModel.SiteName),
                ShowNextPageLink = showNextPageLink,
                ShowPreviousPageLink = showPreviousPageLink,
                NextPage = inModel.Page + 1,
                PreviousPage = inModel.Page - 1,
                ShowBothLinks = showNextPageLink && showPreviousPageLink,
            });
        }