Esempio n. 1
0
        public ActionResult PostsIndex(int blogId, int pageNumber = 1)
        {
            if (pageNumber < 1)
            {
                pageNumber = 1;
            }
            var blog  = blogService.Get(blogId);
            var user  = userService.Get(blog.UserId);
            var model = new PostMainModel(pageNumber, new List <PostModel>(), user, blog);

            if (User.Identity.IsAuthenticated)
            {
                ViewBag.IsMyBlog = user.Email == User.Identity.Name;
            }

            return(View(model));
        }
Esempio n. 2
0
        public PartialViewResult GetBlogPosts(int blogId, int pageNumber = 1)
        {
            var blog = blogService.Get(blogId);
            var user = userService.Get(blog.UserId);

            var allPosts = postService.GetByBlog(blog.Id).ToList();
            var posts    = allPosts.Skip((pageNumber - 1) * itemsToLoad).Take(itemsToLoad);

            var mainModels = new List <PostModel>();

            foreach (var post in posts)
            {
                var tags = tagService.GetByPost(post.Id);
                mainModels.Add(new PostModel(post, tags, wordsInDescription, Description.GetDescription));
            }

            var model = new PostMainModel(pageNumber, mainModels, user, blog);

            ViewBag.HasPrevius = pageNumber > 1;
            ViewBag.HasNext    = allPosts.Count() > pageNumber * itemsToLoad;

            return(PartialView("_GetBlogPosts", model));
        }