コード例 #1
0
ファイル: CommentService.cs プロジェクト: Jscroop/BlogSystem
        /// <summary>
        /// 添加回复型评论的回复
        /// </summary>
        /// <param name="model"></param>
        /// <param name="articleId"></param>
        /// <param name="commentId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task CreateToReplyComment(CreateApplyCommentViewModel model, Guid articleId, Guid commentId, Guid userId)
        {
            var comment = await _commentReplyRepository.GetOneByIdAsync(commentId);

            var toUserId = comment.UserId;

            await _commentReplyRepository.CreateAsync(new CommentReply()
            {
                CommentId = commentId,
                ToUserId  = toUserId,
                ArticleId = articleId,
                UserId    = userId,
                Content   = model.Content
            });
        }
コード例 #2
0
        public async Task <IActionResult> CreateReplyComment(Guid articleId, Guid commentId, CreateApplyCommentViewModel model)
        {
            if (!await _articleService.ExistsAsync(articleId))
            {
                return(NotFound());
            }
            //回复的是正常评论
            if (await _commentService.ExistsAsync(commentId))
            {
                await _commentService.CreateReplyComment(model, articleId, commentId, _userId);

                return(CreatedAtRoute(nameof(GetComments), new { articleId }, model));
            }
            //需要考虑回复的是正常评论还是回复型评论
            if (await _commentService.ReplyExistAsync(commentId))
            {
                await _commentService.CreateToReplyComment(model, articleId, commentId, _userId);

                return(CreatedAtRoute(nameof(GetComments), new { articleId }, model));
            }
            return(NotFound());
        }