public async Task MapAsync(
            PageBlockTypeDisplayModelMapperContext <PageListDataModel> context,
            PageBlockTypeDisplayModelMapperResult <PageListDataModel> result
            )
        {
            var allPageIds = context.Items.SelectManyDistinctModelValues(d => d.PageIds);

            // Page routes are cached and so are the quickest way to get simple page information.
            // If we needed more data we could use a different but slower query to get it.
            var query         = new GetPageRenderSummariesByIdRangeQuery(allPageIds, context.PublishStatusQuery);
            var allPageRoutes = await _contentRepository
                                .WithExecutionContext(context.ExecutionContext)
                                .Pages()
                                .GetByIdRange(allPageIds)
                                .AsRenderSummaries(context.PublishStatusQuery)
                                .ExecuteAsync();

            foreach (var item in context.Items)
            {
                var mapped = new PageListDisplayModel();

                // Here will get the relevant pages and order them correctly.
                mapped.Pages = allPageRoutes
                               .FilterAndOrderByKeys(item.DataModel.PageIds)
                               .ToList();

                result.Add(item, mapped);
            }
        }
Example #2
0
        public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync(
            IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <PageListDataModel> > inputCollection,
            PublishStatusQuery publishStatus
            )
        {
            var allPageIds = inputCollection.SelectManyDistinctModelValues(d => d.PageIds);

            // Page routes are cached and so are the quickest way to get simple page information.
            // If we needed more data we could use a different but slower query to get it.
            var query         = new GetPageRenderDetailsByIdRangeQuery(allPageIds);
            var allPageRoutes = await _pageRepository.GetPageRenderDetailsByIdRangeAsync(query);

            var results = new List <PageBlockTypeDisplayModelMapperOutput>(inputCollection.Count);

            foreach (var input in inputCollection)
            {
                var output = new PageListDisplayModel();

                // Here will get the relevant pages and order them correctly.
                // Additionally if we are viewing the published version of the page
                // then we make sure we only show published pages in the list.

                output.Pages = allPageRoutes
                               .FilterAndOrderByKeys(input.DataModel.PageIds)
                               .ToList();

                // The CreateOutput() method wraps the mapped display
                // model with it's identifier so we can identify later on
                results.Add(input.CreateOutput(output));
            }

            return(results);
        }