Exemplo n.º 1
0
        private async Task <PagedQueryResult <BlogPostSummary> > MapBlogPostsAsync(PagedQueryResult <CustomEntityRenderSummary> customEntityResult)
        {
            var blogPosts = new List <BlogPostSummary>(customEntityResult.Items.Count());

            var imageAssetIds = customEntityResult
                                .Items
                                .Select(i => (BlogPostDataModel)i.Model)
                                .Select(m => m.ThumbnailImageAssetId)
                                .Distinct();

            var images = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds);

            foreach (var customEntity in customEntityResult.Items)
            {
                var model = (BlogPostDataModel)customEntity.Model;

                var blogPost = new BlogPostSummary();
                blogPost.Title               = customEntity.Title;
                blogPost.ShortDescription    = model.ShortDescription;
                blogPost.ThumbnailImageAsset = images.GetOrDefault(model.ThumbnailImageAssetId);
                blogPost.FullPath            = customEntity.PageUrls.FirstOrDefault();
                blogPost.PostDate            = customEntity.CreateDate;

                blogPosts.Add(blogPost);
            }

            return(customEntityResult.ChangeType(blogPosts));
        }
        public async Task MapAsync(
            PageBlockTypeDisplayModelMapperContext <CarouselDataModel> context,
            PageBlockTypeDisplayModelMapperResult <CarouselDataModel> result
            )
        {
            // Find all the image ids to load
            var allImageAssetIds = context
                                   .Items
                                   .SelectMany(m => m.DataModel.Slides)
                                   .Select(m => m.ImageId)
                                   .Where(i => i > 0)
                                   .Distinct();

            // Load image data
            var allImages = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(allImageAssetIds, context.ExecutionContext);

            // Map display model
            foreach (var items in context.Items)
            {
                var output = new CarouselDisplayModel();

                output.Slides = EnumerableHelper
                                .Enumerate(items.DataModel.Slides)
                                .Select(m => new CarouselSlideDisplayModel()
                {
                    Image = allImages.GetOrDefault(m.ImageId),
                    Text  = m.Text,
                    Title = m.Title
                })
                                .ToList();

                result.Add(items, output);
            }
        }
        public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync(
            IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <ContentSplitSectionDataModel> > inputCollection,
            PublishStatusQuery publishStatus
            )
        {
            // Because mapping is done in batch, we have to map multiple images here
            // Fortunately Cofoundry gives us access to repositories that can fetch this data
            // for us

            var imageAssetIds = inputCollection.SelectDistinctModelValuesWithoutEmpty(i => i.ImageAssetId);
            var imageAssets   = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds);

            var results = new List <PageBlockTypeDisplayModelMapperOutput>();

            foreach (var input in inputCollection)
            {
                var output = new ContentSplitSectionDisplayModel();
                output.HtmlText = new HtmlString(input.DataModel.HtmlText);
                output.Title    = input.DataModel.Title;
                output.Image    = imageAssets.GetOrDefault(input.DataModel.ImageAssetId);

                results.Add(input.CreateOutput(output));
            }

            return(results);
        }
Exemplo n.º 4
0
 private Task <IDictionary <int, ImageAssetRenderDetails> > GetMainImages(PagedQueryResult <CustomEntityRenderSummary> customEntityResult)
 {
     return(_imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(customEntityResult
                                                                           .Items
                                                                           .Select(i => (PlayerDataModel)i.Model)
                                                                           .Where(m => !EnumerableHelper.IsNullOrEmpty(m.ImageAssetIds))
                                                                           .Select(m => m.ImageAssetIds.First())
                                                                           .Distinct()));
 }
Exemplo n.º 5
0
        private Task <IDictionary <int, ImageAssetRenderDetails> > GetMainImages(ICollection <CustomEntityRenderSummary> customEntities)
        {
            var imageAssetIds = customEntities
                                .Select(i => (CatDataModel)i.Model)
                                .Where(m => !EnumerableHelper.IsNullOrEmpty(m.ImageAssetIds))
                                .Select(m => m.ImageAssetIds.First())
                                .Distinct();

            return(_imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds));
        }
Exemplo n.º 6
0
        private async Task <ICollection <ImageAssetRenderDetails> > GetImagesAsync(ICollection <int> imageAssetIds)
        {
            if (EnumerableHelper.IsNullOrEmpty(imageAssetIds))
            {
                return(Array.Empty <ImageAssetRenderDetails>());
            }

            var images = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds);

            return(images
                   .FilterAndOrderByKeys(imageAssetIds)
                   .ToList());
        }
        /// <summary>
        /// Here we map the raw custom entity data from Cofoundry into our
        /// own BlogPostSummary which will get sent to be rendered in the
        /// view.
        ///
        /// This code is repeated in HomepageBlogPostsViewComponent for
        /// simplicity, but typically you'd put the code into a shared
        /// mapper or break data access out into it's own shared layer.
        /// </summary>
        private async Task <PagedQueryResult <BlogPostSummary> > MapBlogPostsAsync(
            PagedQueryResult <CustomEntityRenderSummary> customEntityResult,
            PublishStatusQuery ambientEntityPublishStatusQuery
            )
        {
            var blogPosts = new List <BlogPostSummary>(customEntityResult.Items.Count());

            var imageAssetIds = customEntityResult
                                .Items
                                .Select(i => (BlogPostDataModel)i.Model)
                                .Select(m => m.ThumbnailImageAssetId)
                                .Distinct();

            var authorIds = customEntityResult
                            .Items
                            .Select(i => (BlogPostDataModel)i.Model)
                            .Select(m => m.AuthorId)
                            .Distinct();

            var imageLookup = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds);

            var authorQuery  = new GetCustomEntityRenderSummariesByIdRangeQuery(authorIds, ambientEntityPublishStatusQuery);
            var authorLookup = await _customEntityRepository.GetCustomEntityRenderSummariesByIdRangeAsync(authorQuery);

            foreach (var customEntity in customEntityResult.Items)
            {
                var model = (BlogPostDataModel)customEntity.Model;

                var blogPost = new BlogPostSummary();
                blogPost.Title               = customEntity.Title;
                blogPost.ShortDescription    = model.ShortDescription;
                blogPost.ThumbnailImageAsset = imageLookup.GetOrDefault(model.ThumbnailImageAssetId);
                blogPost.FullPath            = customEntity.PageUrls.FirstOrDefault();
                blogPost.PostDate            = customEntity.PublishDate;

                var author = authorLookup.GetOrDefault(model.AuthorId);
                if (author != null)
                {
                    blogPost.AuthorName = author.Title;
                }

                blogPosts.Add(blogPost);
            }

            return(customEntityResult.ChangeType(blogPosts));
        }
Exemplo n.º 8
0
        public async Task MapAsync(
            PageBlockTypeDisplayModelMapperContext <ContentSplitSectionDataModel> context,
            PageBlockTypeDisplayModelMapperResult <ContentSplitSectionDataModel> result
            )
        {
            var imageAssetIds = context.Items.SelectDistinctModelValuesWithoutEmpty(i => i.ImageAssetId);
            var imageAssets   = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds, context.ExecutionContext);

            foreach (var item in context.Items)
            {
                var displayModel = new ContentSplitSectionDisplayModel();
                displayModel.HtmlText = new HtmlString(item.DataModel.HtmlText);
                displayModel.Title    = item.DataModel.Title;
                displayModel.Image    = imageAssets.GetOrDefault(item.DataModel.ImageAssetId);

                result.Add(item, displayModel);
            }
        }
        public async Task MapAsync(
            PageBlockTypeDisplayModelMapperContext <ContentSplitSectionDataModel> context,
            PageBlockTypeDisplayModelMapperResult <ContentSplitSectionDataModel> result
            )
        {
            // Because mapping is done in batch, we have to map multiple images here
            // Fortunately Cofoundry gives us access to repositories that can fetch this data
            // for us
            var imageAssetIds = context.Items.SelectDistinctModelValuesWithoutEmpty(i => i.ImageAssetId);
            var imageAssets   = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds, context.ExecutionContext);

            foreach (var item in context.Items)
            {
                var displayModel = new ContentSplitSectionDisplayModel();
                displayModel.HtmlText = new HtmlString(item.DataModel.HtmlText);
                displayModel.Title    = item.DataModel.Title;
                displayModel.Image    = imageAssets.GetOrDefault(item.DataModel.ImageAssetId);

                result.Add(item, displayModel);
            }
        }
Exemplo n.º 10
0
        public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync(
            IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <ContentSplitSectionDataModel> > inputCollection,
            PublishStatusQuery publishStatus
            )
        {
            var imageAssetIds = inputCollection.SelectDistinctModelValuesWithoutEmpty(i => i.ImageAssetId);;
            var imageAssets   = await _imageAssetRepository.GetImageAssetRenderDetailsByIdRangeAsync(imageAssetIds);

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

            foreach (var input in inputCollection)
            {
                var output = new ContentSplitSectionDisplayModel();
                output.HtmlText = new HtmlString(input.DataModel.HtmlText);
                output.Title    = input.DataModel.Title;
                output.Image    = imageAssets.GetOrDefault(input.DataModel.ImageAssetId);

                results.Add(input.CreateOutput(output));
            }

            return(results);
        }