public async Task <AdminCommentIndexDto> GetAdminIndexAsync(AdminCommentIndexFilter filter) { filter.CheckArgumentIsNull(nameof(filter)); var query = _repository .Query() .Where(_ => _.Post.WebsiteId == _userContext.WebsiteId) .SetFilter(filter); var result = new AdminCommentIndexDto(); result.DataSource.TotalCount = await query.CountAsync(); result.DataSource.PageIndex = filter.PageIndex; result.DataSource.PageSize = filter.PageSize; query = query .Skip(filter.StartIndex) .Take(filter.PageSize); var comments = await query.ToListAsync(); await setCommentsToViewed(comments); await setCommentsToRead(comments); result.DataSource.Items = comments .Select(_ => _.Adapt <AdminCommentIndexItemDto>()) .ToList(); return(await Task.FromResult(result)); }
public static IQueryable <Comment> SetFilter( this IQueryable <Comment> query, AdminCommentIndexFilter filter) { filter.CheckArgumentIsNull(nameof(filter)); if (!filter.Title.IsNullOrEmpty()) { query = query.Where(_ => _.Title.Contains(filter.Title)); } if (!filter.Email.IsNullOrEmpty()) { query = query.Where(_ => _.Email.Contains(filter.Email)); } if (filter.Status.HasValue) { query = query.Where(_ => _.Status == filter.Status.Value); } return(query); }