public async Task <PagedResultDto <CommentListDto> > GetPaged(GetCommentsInput input) { var query = from entity in _commentRepository.GetAll() .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), a => a.Text.Contains(input.FilterText)) join post in _postRepository.GetAll() on entity.PostId equals post.Id into postJoind from post in postJoind.DefaultIfEmpty() join replied in _commentRepository.GetAll() on entity.RepliedCommentId equals replied.Id into repliedJoind from replied in repliedJoind.DefaultIfEmpty() select new CommentListDto() { Id = entity.Id, PostId = entity.PostId, RepliedCommentId = entity.RepliedCommentId, Text = entity.Text, Title = post.Title, RepliedCommentTest = replied != null ? replied.Text : "" }; var count = await query.CountAsync(); var commentList = await query .PageBy(input) .ToListAsync(); return(new PagedResultDto <CommentListDto>(count, commentList)); }
public async Task <List <CommentOutput> > GetComments(GetCommentsInput input) { var comments = await Repository .Where(c => c.ObjectId == input.ObjectId && c.ObjectTypeEnum == input.ObjectTypeEnum) .WhereIf(input.InteractionId != Guid.Empty, c => c.InteractionId == input.InteractionId) .ToListAsync(); var parentComments = comments .Where(c => c.ParentId == null) .Select(c => Mapper.Map <CommentOutput>(c)) .ToList(); var output = new List <CommentOutput>(); foreach (var comment in parentComments) { // TODO: Bad Performance comment.Children = await FindSubChildren(comment.Id); output.Add(comment); } return(output); }