public IActionResult Read(string slug) { if (string.IsNullOrWhiteSpace(slug)) { return(NotFound()); } var strSlug = slug.Trim().ToLower(); var post = PostRepository.GetPostBySlug(strSlug); if (null != post) { // get tags var tags = PostTagAssociationRepository.GetTagsByPost(post.Id); // get categories var cats = PostCategoryAssociationRepository.GetCatsByPost(post.Id); // get comments var cmts = CommentRepository.GetCommentsByPostId(post.Id); var viewModel = new PostReadViewModel() { Post = post, Tags = tags?.ToList() ?? new List <Tag>(), Categories = cats?.ToList() ?? new List <Category>(), Comments = cmts?.ToList() ?? new List <Comment>() }; return(View(viewModel)); } else { return(NotFound()); } }
public PostController(ILogger <PostController> logger, IOptions <AppSettings> settings, IConfiguration configuration, IHttpContextAccessor accessor) : base(logger, settings, configuration) { _accessor = accessor; PostRepository = new PostRepository(); PostTagAssociationRepository = new PostTagAssociationRepository(); PostCategoryAssociationRepository = new PostCategoryAssociationRepository(); CommentRepository = new CommentRepository(); }