public ActionResult Index(int page = 1) { var blogs = _blogRepo.GetAllBlogPosts(); //get the 5 blog posts for the relevant page var blogsToShow = blogs .OrderByDescending(x => x.Date) .Skip((page - 1) * pageSize) .Take(pageSize); //create view model and pass in meta page info var model = new BlogIndexVM { Page = page, HasOlderPages = blogs.Count() > page * pageSize, HasNewerPages = page > 1 }; //add blog previews to model with trimmed text foreach (var blogPost in blogsToShow) { model.Blogs.Add(new BlogIndexBlog { Date = blogPost.Date.ToString("MMMM d, yyyy"), Id = blogPost.Id, Title = blogPost.Title, RouteName = blogPost.RouteName, TrimmedText = blogPost.Text.Length <= 180 ? blogPost.Text : blogPost.Text.Substring(0, 180) + " ..." }); } return(View(model)); }
public async Task <BlogPostsResult> GetAllBlogPosts() { var results = await _blogPostRepository.GetAllBlogPosts(); if (results.Count == 0) { return new BlogPostsResult { Data = results, Details = new ResultDetails { Message = "None were found.", ResultStatus = ResultStatus.Warning } } } ; return(new BlogPostsResult { Data = results, Details = new ResultDetails { ResultStatus = ResultStatus.Success } }); }
//gets all blog posts and converts them into correct //format for view model public ViewResult Blog() { var posts = _blogRepo.GetAllBlogPosts(); var model = new AdminBlogVM(); foreach (var blogPost in posts) { model.BlogPosts.Add(new AdminBlogPartial { Date = blogPost.Date.ToString("MMMM d, yyyy"), Id = blogPost.Id, Title = blogPost.Title }); } return(View(model)); }
// // GET: /BlogPost/ public ViewResult Index() { return(View(_repository.GetAllBlogPosts())); }
// GET /api/values public IEnumerable <BlogPost> Get() { return(_repository.GetAllBlogPosts()); }