Пример #1
0
        /// <summary>
        /// Returns a listing of blog posts
        /// </summary>
        /// <param name="posts">Posts to be displayed</param>
        /// <param name="count">Number of posts being displayed</param>
        /// <param name="page">Page number of the current page</param>
        /// <param name="viewName">Name of the view to render</param>
        /// <param name="viewModel">View model to pass to the view</param>
        /// <returns>Post listing</returns>
        private ActionResult Listing(IEnumerable<PostModel> posts, int count, int page, string viewName = null, ListingViewModel viewModel = null)
        {
            if (viewName == null)
                viewName = Views.Index;

            if (viewModel == null)
                viewModel = new ListingViewModel();

            var pages = (int)Math.Ceiling((double)count / ITEMS_PER_PAGE);

            using (_profiler.Step("Building post ViewModels"))
            {
                viewModel.Posts = posts.Select(post => new PostViewModel
                {
                    Post = post,
                    ShortUrl = ShortUrl(post),
                    SocialNetworks = _socialManager.ShareUrls(post, Url.BlogPostAbsolute(post), ShortUrl(post))
                });
            }
            viewModel.TotalCount = count;
            viewModel.Page = page;
            viewModel.TotalPages = pages;
            return View(viewName, viewModel);
        }
Пример #2
0
        /// <summary>
        /// Returns a listing of blog posts
        /// </summary>
        /// <param name="posts">Posts to be displayed</param>
        /// <param name="count">Number of posts being displayed</param>
        /// <param name="page">Page number of the current page</param>
        /// <param name="viewName">Name of the view to render</param>
        /// <param name="viewModel">View model to pass to the view</param>
        /// <returns>Post listing</returns>
        private ActionResult Listing(IEnumerable<PostModel> posts, int count, int page, string viewName = null, ListingViewModel viewModel = null)
        {
            if (viewName == null)
                viewName = "Index";

            if (viewModel == null)
                viewModel = new ListingViewModel();

            var pages = (int)Math.Ceiling((double)count / ITEMS_PER_PAGE);

            if (page > pages)
                return NotFound();

            viewModel.Posts = posts.Select(post => new PostViewModel
            {
                Post = post,
                ShortUrl = ShortUrl(post),
                SocialNetworks = GetSocialNetworks(post)
            });
            viewModel.TotalCount = count;
            viewModel.Page = page;
            viewModel.TotalPages = pages;
            return View(viewName, viewModel);
        }