public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync( IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <ImageDataModel> > inputCollection, PublishStatusQuery publishStatusQuery ) { var imageAssetIds = inputCollection.SelectDistinctModelValuesWithoutEmpty(i => i.ImageId); var imagesQuery = new GetImageAssetRenderDetailsByIdRangeQuery(imageAssetIds); var images = await _queryExecutor.ExecuteAsync(imagesQuery); var results = new List <PageBlockTypeDisplayModelMapperOutput>(inputCollection.Count); foreach (var input in inputCollection) { var output = new ImageDisplayModel() { AltText = input.DataModel.AltText, LinkPath = input.DataModel.LinkPath, LinkTarget = input.DataModel.LinkTarget }; var image = images.GetOrDefault(input.DataModel.ImageId); output.Source = _imageAssetRouteLibrary.ImageAsset(image); results.Add(input.CreateOutput(output)); } return(results); }
public async Task MapAsync( PageBlockTypeDisplayModelMapperContext <ImageDataModel> context, PageBlockTypeDisplayModelMapperResult <ImageDataModel> result ) { var imageAssetIds = context.Items.SelectDistinctModelValuesWithoutEmpty(i => i.ImageId); var imagesQuery = new GetImageAssetRenderDetailsByIdRangeQuery(imageAssetIds); var images = await _queryExecutor.ExecuteAsync(imagesQuery, context.ExecutionContext); foreach (var item in context.Items) { var displayModel = new ImageDisplayModel() { AltText = item.DataModel.AltText, LinkPath = item.DataModel.LinkPath, LinkTarget = item.DataModel.LinkTarget }; var image = images.GetOrDefault(item.DataModel.ImageId); displayModel.Source = _imageAssetRouteLibrary.ImageAsset(image); result.Add(item, displayModel); } }