Esempio n. 1
0
 public async Task <ApiResult <PageList <CommentPageResponse> > > QueryCommentPageAsync([FromBody] CommentPageRequest request)
 {
     return(await _commentService.QueryCommentPageAsync(request, null));
 }
Esempio n. 2
0
        /// <summary>
        /// 查询评论分页数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <ApiResult <PageList <CommentPageResponse> > > QueryCommentPageAsync(CommentPageRequest request, long?userId)
        {
            var response = new ApiResult <PageList <CommentPageResponse> >();

            try
            {
                var comments = await(from c in _commentRepository.TableNotTracking
                                     where c.ArticleId == request.ArticleId && c.Status == 1 && c.IsReply == 0
                                     orderby c.CreateTime descending
                                     select new CommentPageResponse
                {
                    Id         = c.Id,
                    ArticleId  = c.ArticleId,
                    UserId     = c.UserId,
                    Content    = c.Content,
                    Like       = c.Like,
                    Reply      = c.Reply,
                    UserName   = c.UserName,
                    CreateTime = c.CreateTime
                }).ToPageListAsync(request.PageParm.Page, request.PageParm.Size);

                foreach (var c in comments.Data)
                {
                    c.Reply = await _commentRepository.TableNotTracking
                              .CountAsync(item => item.IsReply == 1 && item.ReplyCommentId == c.Id && item.Status == 1);

                    var replyComments = await(from rc in _commentRepository.TableNotTracking
                                              where rc.IsReply == 1 && rc.ReplyCommentId == c.Id && rc.Status == 1
                                              orderby rc.CreateTime descending
                                              select new CommentSubPageResponse
                    {
                        Id                = rc.Id,
                        ArticleId         = rc.ArticleId,
                        UserId            = rc.UserId,
                        Content           = rc.Content,
                        Like              = rc.Like,
                        Reply             = rc.Reply,
                        UserName          = rc.UserName,
                        CreateTime        = rc.CreateTime,
                        SubReplyUserId    = rc.ReplySubUserId,
                        SubReplyUserName  = rc.ReplySubUserName,
                        SubReplyCommentId = rc.ReplySubCommentId
                    })
                                        .FirstOrDefaultAsync();
                    c.FirstReplyComment = replyComments;
                }

                response.Code    = Code.Ok;
                response.Message = "查询成功";
                response.Data    = comments;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError($"查询评论分页异常;method={nameof(ArticleCommentAsync)};param={request.ToJson()};exception messges={ex.Message}");
                response.Code    = Code.Error;
                response.Message = $"查询评论分页异常:{ex.Message}";
                return(response);
            }
        }