Exemple #1
0
        public async Task <ActionResult <CommentVm> > GetBlogPostCommentAsync(int id, int commentId)
        {
            var blogPost = await _blogPostsRepository.ReadByIdAsync(id);

            if (blogPost.Status != EnBlogPostStatus.Published)
            {
                return(BadRequest());
            }

            var comment = await _blogPostCommentsRepository.ReadByIdAsync(commentId);

            if (comment is null)
            {
                return(NotFound());
            }

            return(_mapper.Map <CommentVm>(comment));
        }
        public async Task <ActionResult> UpdateBlogPostAsync(int id, UpdateBlogPostVm updateBlogPostVm)
        {
            var blogPost = await _blogPostsRepository.ReadByIdAsync(id);

            if (blogPost is null)
            {
                return(NotFound());
            }

            _mapper.Map(updateBlogPostVm, blogPost);

            if (updateBlogPostVm.Status == EnBlogPostStatus.Published)
            {
                blogPost.PublishedAt = DateTime.Now;
            }

            await _blogPostsRepository.UpdateAsync(blogPost);

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <int> > CreateAdminBlogPostCommentAsync(int id,
                                                                                [FromBody] CreateAdminCommentVm createCommentVm)
        {
            var blogPost = await _blogPostsRepository.ReadByIdAsync(id);

            var comment = _mapper.Map <Comment>(createCommentVm);

            comment.BlogPostId = blogPost.Id;

            await _blogPostCommentsRepository.CreateAsync(comment);

            return(comment.Id);
        }