public void Test()
        {
            CommentSearchDto commentSearchDto = new CommentSearchDto()
            {
                SubjectId = Guid.Parse("5dc6bb5f-9cfa-ff24-00a8-d50e576b275a")
            };

            long userId = 7;
            List <CommentDto> comments = _baseRepository
                                         .Select
                                         .Include(r => r.UserInfo)
                                         .Include(r => r.RespUserInfo)
                                         .IncludeMany(r => r.Childs.Take(2), t => t.Include(u => u.UserInfo))
                                         .IncludeMany(r => r.UserLikes)
                                         .WhereIf(commentSearchDto.SubjectId != null, r => r.SubjectId == commentSearchDto.SubjectId)
                                         .Where(r => r.RootCommentId == commentSearchDto.RootCommentId)
                                         .OrderByDescending(!commentSearchDto.RootCommentId.HasValue, r => r.CreateTime)
                                         .OrderBy(commentSearchDto.RootCommentId.HasValue, r => r.CreateTime)
                                         .ToPagerList(commentSearchDto, out long totalCount)
                                         .Select(r =>
            {
                CommentDto commentDto = Mapper.Map <CommentDto>(r);


                commentDto.TopComment = r.Childs.ToList().Select(u =>
                {
                    CommentDto childrenDto = Mapper.Map <CommentDto>(u);
                    return(childrenDto);
                }).ToList();
                commentDto.IsLiked = r.UserLikes.Where(u => u.CreateUserId == userId).IsNotEmpty();
                return(commentDto);
            }).ToList();
            //return new PagedResultDto<CommentDto>(comments, totalCount);
        }
        public PagedResultDto <CommentDto> Get([FromQuery] CommentSearchDto commentSearchDto)
        {
            long?userId = _currentUser.Id;
            List <CommentDto> comments = _commentAuditBaseRepository
                                         .Select
                                         .Include(r => r.UserInfo)
                                         .Include(r => r.RespUserInfo)
                                         .IncludeMany(r => r.Childs, //.Take(2)
                                                      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).ToList()
                                         //.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.Avatar = _currentUser.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 = _currentUser.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));
        }
        public void GetAll()
        {
            CommentSearchDto commentSearchDto = new CommentSearchDto()
            {
                Count = 10,
                Page  = 11
            };
            var comment0 = _baseRepository
                           .Select
                           .OrderByDescending(r => r.CreateTime)
                           .Count(out long count1);

            var comments = _baseRepository
                           .Select
                           .OrderByDescending(r => r.CreateTime)
                           .Page(commentSearchDto.Page + 1, commentSearchDto.Count)
                           .ToList();
        }
 public void Gets()
 {
     CommentSearchDto commentSearchDto = new CommentSearchDto()
     {
         SubjectId = Guid.Parse("5dc6bb5f-9cfa-ff24-00a8-d50e576b275a")
     };
     dynamic comments = _baseRepository
                        .Select
                        .Include(r => r.UserInfo)
                        .From <UserLike>(
         (z, zzc) =>
         z.LeftJoin(u => u.Id == zzc.SubjectId)
         )
                        .ToList((s, za) => new
     {
         comment = s,
         za.SubjectId
     });
 }
Пример #5
0
        public PagedResultDto <CommentDto> GetAll([FromQuery] CommentSearchDto commentSearchDto)
        {
            List <CommentDto> comments = _commentAuditBaseRepository
                                         .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)
                                         .ToPagerList(commentSearchDto, out long totalCount)
                                         .Select(r =>
            {
                CommentDto commentDto = _mapper.Map <CommentDto>(r);

                if (commentDto.UserInfo != null)
                {
                    commentDto.UserInfo.Avatar = _currentUser.GetFileUrl(commentDto.UserInfo.Avatar);
                }
                return(commentDto);
            }).ToList();

            return(new PagedResultDto <CommentDto>(comments, totalCount));
        }
Пример #6
0
 public async Task <PagedResultDto <CommentDto> > GetListAsync([FromQuery] CommentSearchDto commentSearchDto)
 {
     return(await _commentService.GetListAsync(commentSearchDto));
 }
Пример #7
0
 private long GetCommentCount(CommentSearchDto commentSearchDto)
 {
     return(_commentAuditBaseRepository
            .Select
            .Where(r => r.IsDeleted == false && r.SubjectId == commentSearchDto.SubjectId).Count());
 }
Пример #8
0
 public Task <PagedResultDto <CommentDto> > GetListByArticleAsync([FromQuery] CommentSearchDto commentSearchDto)
 {
     return(_commentService.GetListByArticleAsync(commentSearchDto));
 }