Exemplo n.º 1
0
        public async Task <List <Comment> > Filter(CommentFilterInDto filterOptions)
        {
            var filtered = _context.Comments
                           .Include(c => c.Post)
                           .Include(c => c.User)
                           .Where(c => (
                                      (filterOptions.ParentId == null || filterOptions.ParentId == c.ParentId) &&
                                      (filterOptions.PostId == null || filterOptions.PostId == c.PostId) &&
                                      (filterOptions.UserId == null || filterOptions.UserId == c.UserId) &&
                                      (filterOptions.StatusId == null || filterOptions.StatusId == c.StatusId) &&
                                      (filterOptions.CategoryId == null || filterOptions.CategoryId == c.CategoryId)
                                      ));
            var ordered = filterOptions.CreateTimeDesc
                ? filtered.OrderByDescending(c => c.CreateTime)
                : filtered.OrderBy(c => c.CreateTime);

            return(await ordered.SkipTakePaging(filterOptions).ToListAsync());
        }
Exemplo n.º 2
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <Comment> > > > GetComments([FromQuery] CommentFilterInDto filterOptions)
 {
     return(Ok(ResultOutDtoBuilder
               .Success(await _commentService.Filter(filterOptions))));
 }