public IActionResult Blog(string seriesRef, string tag, [FromServices] IBlogProvider blogs) { return(View(new BlogIndexViewModel { Series = blogs.GetBlogSeries() .Where(s => seriesRef == null || s.Series.Reference == seriesRef) .Where(s => tag == null || s.Series.Tags.Contains(tag)), TagFilter = tag })); }
public IActionResult BlogPost(string seriesRef, string postIndex, [FromServices] IBlogProvider blogs) { var series = blogs.GetBlogSeries().FirstOrDefault(s => s.Series.Reference == seriesRef); if (series == null) { return(Redirect("/Blog")); } BlogPost lastBlog = null; BlogPost currentBlog = null; BlogPost nextBlog = null; var postIndexNumString = postIndex.Split('-').FirstOrDefault(); // Allows SEO keywords after the post index. var isNumber = Int32.TryParse(postIndexNumString, out int postIndexValue); if (!isNumber) { return(Redirect($"/Blog/{seriesRef}")); } if (postIndexValue > 0 && series.Posts.Count > 1) { lastBlog = series.Posts[postIndexValue - 1]; } if (postIndexValue < series.Posts.Count) { currentBlog = series.Posts[postIndexValue]; } else { return(Redirect($"/Blog/{seriesRef}")); } if (postIndexValue < series.Posts.Count - 1) { nextBlog = series.Posts[postIndexValue + 1]; } return(View(new BlogPostViewModel { Series = series.Series, LastPost = lastBlog, CurrentPost = currentBlog, NextPost = nextBlog })); }