public async Task <PagedQueryResult <PageTemplateSummary> > ExecuteAsync(SearchPageTemplateSummariesQuery query, IExecutionContext executionContext) { var dbPagedResult = await CreateQuery(query).ToPagedResultAsync(query); var allPageTemplateIds = dbPagedResult .Items .Select(p => p.PageTemplate.PageTemplateId) .ToList(); var templatePageCounts = await GetPageCounts(allPageTemplateIds); Dictionary <int, int> pageRegionCounts = await GetTemplateRegionCounts(); foreach (var dbPagedResultItem in dbPagedResult.Items) { dbPagedResultItem.NumPages = templatePageCounts.GetOrDefault(dbPagedResultItem.PageTemplate.PageTemplateId); dbPagedResultItem.NumRegions = pageRegionCounts.GetOrDefault(dbPagedResultItem.PageTemplate.PageTemplateId); } var mappedResults = dbPagedResult .Items .Select(_pageTemplateSummaryMapper.Map); return(dbPagedResult.ChangeType(mappedResults)); }
private IQueryable <PageTemplateSummaryQueryModel> CreateQuery(SearchPageTemplateSummariesQuery query) { var dbQuery = _dbContext .PageTemplates .AsNoTracking() .AsQueryable(); // Filter by group if (!string.IsNullOrWhiteSpace(query.Name)) { dbQuery = dbQuery.Where(p => p.FileName.Contains(query.Name) || p.Description.Contains(query.Name)); } return(dbQuery .OrderBy(p => p.FileName) .Select(t => new PageTemplateSummaryQueryModel() { PageTemplate = t, //NumPages = t.PageVersions // .GroupBy(p => p.PageId) // .Count(), //NumRegions = t // .PageTemplateRegions // .Count() })); }
private IQueryable <PageTemplateSummary> CreateQuery(SearchPageTemplateSummariesQuery query) { var dbQuery = _dbContext .PageTemplates .AsNoTracking() .AsQueryable(); // Filter by group if (!string.IsNullOrWhiteSpace(query.Name)) { dbQuery = dbQuery.Where(p => p.FileName.Contains(query.Name) || p.Description.Contains(query.Name)); } return(dbQuery .OrderBy(p => p.FileName) .ProjectTo <PageTemplateSummary>()); }
public IEnumerable <IPermissionApplication> GetPermissions(SearchPageTemplateSummariesQuery query) { yield return(new PageTemplateReadPermission()); }
public async Task <PagedQueryResult <PageTemplateSummary> > ExecuteAsync(SearchPageTemplateSummariesQuery query, IExecutionContext executionContext) { var result = await CreateQuery(query).ToPagedResultAsync(query); return(result); }