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)); }
private async Task<PagedQueryResult<BlogPostSummary>> MapBlogPostsAsync( PagedQueryResult<CustomEntityRenderSummary> customEntityResult, PublishStatusQuery ambientEntityPublishStatusQuery) { var blogPosts = new List<BlogPostSummary>(); var imageAssetIds = customEntityResult .Items .Select(i => (BlogPostDataModel)i.Model) .Where(m => m.ThumbnailImageAssetId != null) .Select(m => m.ThumbnailImageAssetId.Value) .Distinct(); var imageLookup = await _contentRepository .ImageAssets() .GetByIdRange(imageAssetIds) .AsRenderDetails() .ExecuteAsync(); 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; blogPosts.Add(blogPost); } return customEntityResult.ChangeType(blogPosts); }
private PagedQueryResult <CatSummary> MapCats( PagedQueryResult <CustomEntityRenderSummary> customEntityResult, IDictionary <int, ImageAssetRenderDetails> images, IDictionary <int, int> allLikeCounts ) { var cats = new List <CatSummary>(customEntityResult.Items.Count()); foreach (var customEntity in customEntityResult.Items) { var model = (CatDataModel)customEntity.Model; var cat = new CatSummary(); cat.CatId = customEntity.CustomEntityId; cat.Name = customEntity.Title; cat.Description = model.Description; cat.TotalLikes = allLikeCounts.GetOrDefault(customEntity.CustomEntityId); if (!EnumerableHelper.IsNullOrEmpty(model.ImageAssetIds)) { cat.MainImage = images.GetOrDefault(model.ImageAssetIds.FirstOrDefault()); } cats.Add(cat); } return(customEntityResult.ChangeType(cats)); }
private PagedQueryResult <PlayerSummary> MapPlayers( PagedQueryResult <CustomEntityRenderSummary> customEntityResult, IDictionary <int, ImageAssetRenderDetails> images, IDictionary <int, int> allLikeCounts ) { var players = new List <PlayerSummary>(customEntityResult.Items.Count()); foreach (var(customEntity, model, player) in from customEntity in customEntityResult.Items let model = (PlayerDataModel)customEntity.Model let player = new PlayerSummary() select(customEntity, model, player)) { player.PlayerId = customEntity.CustomEntityId; player.Name = customEntity.Title; player.Description = model.Description; player.TotalLikes = allLikeCounts.GetOrDefault(customEntity.CustomEntityId); if (!EnumerableHelper.IsNullOrEmpty(model.ImageAssetIds)) { player.MainImage = images.GetOrDefault(model.ImageAssetIds.FirstOrDefault()); } players.Add(player); } return(customEntityResult.ChangeType(players)); }
/// <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)); }
private PagedQueryResult <FamilySummary> MapFamily(PagedQueryResult <CustomEntityRenderSummary> familyCustomEntities, IDictionary <int, ImageAssetRenderDetails> allMainImages, ICollection <CustomEntityRenderSummary> allParents) { var families = new List <FamilySummary>(familyCustomEntities.Items.Count()); foreach (var entity in familyCustomEntities.Items) { var model = (FamilyDataModel)entity.Model; var family = new FamilySummary(); family.FamilyId = entity.CustomEntityId; family.Address = model.Address; family.Description = model.Description; family.MastheadTitle = getMastHeadTitle(allParents); family.WeddingAnniversary = model.WeddingAnniversary; if (model.DisplayImageId != null) { family.DisplayImage = allMainImages.GetOrDefault(model.DisplayImageId); } families.Add(family); } return(familyCustomEntities.ChangeType(families)); }
/// <summary> /// aps a set of paged EF CustomEntityVersion records for a single custom entity into /// CustomEntityVersionSummary objects. /// </summary> /// <param name="customEntityId">Id of the custom entity that these versions belong to.</param> /// <param name="dbResult">Paged result set of records to map.</param> public PagedQueryResult <CustomEntityVersionSummary> MapVersions(int customEntityId, PagedQueryResult <CustomEntityVersion> dbResult) { if (dbResult == null) { throw new ArgumentNullException(nameof(dbResult)); } if (customEntityId <= 0) { throw new ArgumentOutOfRangeException(nameof(customEntityId)); } // We should only check for the latested published version on the first page // as it will only be 1st or 2nd in the list (depending on whether there is a draft) bool hasLatestPublishVersion = dbResult.PageNumber > 1; var results = new List <CustomEntityVersionSummary>(dbResult.Items.Count); foreach (var dbVersion in dbResult.Items.OrderByLatest()) { if (dbVersion.CustomEntityId != customEntityId) { var msg = $"Invalid CustomEntityId. CustomEntityVersionSummaryMapper.MapVersions is designed to map versions for a single custom entity only. Excepted CustomEntityId {customEntityId} got {dbVersion.CustomEntityId}"; throw new Exception(msg); } var result = MapVersion(dbVersion); if (!hasLatestPublishVersion && result.WorkFlowStatus == WorkFlowStatus.Published) { result.IsLatestPublishedVersion = true; hasLatestPublishVersion = true; } results.Add(result); } return(dbResult.ChangeType(results)); }
private async Task <PagedQueryResult <FlowerSummary> > MapFlowers( PagedQueryResult <CustomEntityRenderSummary> customEntityResult, IDictionary <int, ImageAssetRenderDetails> images, int categoryFilter ) { var Flowers = new List <FlowerSummary>(customEntityResult.Items.Count()); foreach (var customEntity in customEntityResult.Items) { var model = (FlowerDataModel)customEntity.Model; var Flower = new FlowerSummary(); Flower.FlowerId = customEntity.CustomEntityId; Flower.Name = customEntity.Title; Flower.Description = model.Description; Flower.Category = await GetCategoryAsync(model.CategoryId); Flower.Price = model.Price; Flower.Count = model.Count; if (!EnumerableHelper.IsNullOrEmpty(model.ImageAssetIds)) { Flower.MainImage = images.GetOrDefault(model.ImageAssetIds.FirstOrDefault()); } if (categoryFilter == 0) { Flowers.Add(Flower); } else if (Flower.Category.CategoryId == categoryFilter) { Flowers.Add(Flower); } } return(customEntityResult.ChangeType(Flowers)); }