Beispiel #1
0
        public async Task <PagedResultDto <CommentDto> > GetListAsync([FromQuery] CommentSearchDto commentSearchDto)
        {
            List <CommentDto> comments = (await _commentRepository
                                          .Select
                                          .Include(r => r.UserInfo)
                                          .WhereIf(commentSearchDto.SubjectId.HasValue, r => r.SubjectId == commentSearchDto.SubjectId)
                                          .WhereIf(commentSearchDto.Text.IsNotNullOrEmpty(), r => r.Text.Contains(commentSearchDto.Text))
                                          .OrderByDescending(r => r.CreateTime)
                                          .ToPagerListAsync(commentSearchDto, out long totalCount)
                                          )
                                         .Select(r =>
            {
                CommentDto commentDto = Mapper.Map <CommentDto>(r);

                if (commentDto.UserInfo != null)
                {
                    commentDto.UserInfo.Avatar = _fileRepository.GetFileUrl(commentDto.UserInfo.Avatar);
                }

                return(commentDto);
            }).ToList();

            return(new PagedResultDto <CommentDto>(comments, totalCount));
        }
Beispiel #2
0
 private long GetCommentCount(CommentSearchDto commentSearchDto)
 {
     return(_commentRepository
            .Select
            .Where(r => r.IsDeleted == false && r.SubjectId == commentSearchDto.SubjectId).Count());
 }
Beispiel #3
0
        public async Task <PagedResultDto <CommentDto> > GetListByArticleAsync([FromQuery] CommentSearchDto commentSearchDto)
        {
            long?userId = CurrentUser.Id;
            List <CommentDto> comments = (await _commentRepository
                                          .Select
                                          .Include(r => r.UserInfo)
                                          .Include(r => r.RespUserInfo)
                                          .IncludeMany(r => r.Childs, t => t.Include(u => u.UserInfo).Include(u => u.RespUserInfo).IncludeMany(u => u.UserLikes))
                                          .IncludeMany(r => r.UserLikes)
                                          .WhereCascade(x => x.IsDeleted == false)
                                          .WhereIf(commentSearchDto.SubjectId.HasValue, r => r.SubjectId == commentSearchDto.SubjectId)
                                          .Where(r => r.RootCommentId == commentSearchDto.RootCommentId) // && r.IsAudit == true
                                          .OrderByDescending(!commentSearchDto.RootCommentId.HasValue, r => r.CreateTime)
                                          .OrderBy(commentSearchDto.RootCommentId.HasValue, r => r.CreateTime)
                                          .Page(commentSearchDto.Page + 1, commentSearchDto.Count).ToListAsync())
                                         //.ToPagerList(commentSearchDto, out long totalCount
                                         .Select(r =>
            {
                CommentDto commentDto = Mapper.Map <CommentDto>(r);
                if (commentDto.IsAudit == false)
                {
                    commentDto.Text = "[该评论因违规被拉黑]";
                }

                if (commentDto.UserInfo == null)
                {
                    commentDto.UserInfo = new OpenUserDto("该用户已被系统删除");
                }
                else
                {
                    commentDto.UserInfo.Avatar = _fileRepository.GetFileUrl(commentDto.UserInfo.Avatar);
                }


                commentDto.IsLiked =
                    userId != null && r.UserLikes.Where(u => u.CreateUserId == userId).IsNotEmpty();

                commentDto.TopComment = r.Childs.ToList().Select(u =>
                {
                    CommentDto childrenDto = Mapper.Map <CommentDto>(u);
                    if (childrenDto.UserInfo != null)
                    {
                        childrenDto.UserInfo.Avatar = _fileRepository.GetFileUrl(childrenDto.UserInfo.Avatar);
                    }

                    if (childrenDto.IsAudit == false)
                    {
                        childrenDto.Text = "[该评论因违规被拉黑]";
                    }

                    childrenDto.IsLiked =
                        userId != null && u.UserLikes.Where(z => z.CreateUserId == userId).IsNotEmpty();
                    return(childrenDto);
                }).ToList();
                return(commentDto);
            }).ToList();

            //计算一个文章多少个评论
            long totalCount = GetCommentCount(commentSearchDto);

            return(new PagedResultDto <CommentDto>(comments, totalCount));
        }