示例#1
0
        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 CategoryController(ILogger <CategoryController> logger,
                           IOptions <AppSettings> settings,
                           IConfiguration configuration,
                           IHttpContextAccessor accessor)
     : base(logger, settings, configuration)
 {
     _accessor          = accessor;
     CategoryRepository = new CategoryRepository();
     PostCategoryAssociationRepository = new PostCategoryAssociationRepository();
 }