public async Task <IHtmlContent> GetContentByKeyAsync(string contentKey) { // Cofoundry is missing a query to get a custom entity by the url slug, so for now let's do the lookup manually // and i'll get that built in soon var dbResult = _dbContext .CustomEntities .AsNoTracking() .Where(c => c.CustomEntityDefinitionCode == ContentCustomEntityDefintion.DefinitionCode && c.UrlSlug == contentKey) .FirstOrDefault(); if (dbResult == null) { return(null); } // What we'll end up with is an equivalent of this code, but instead of using the custom entity id, you'll // be able to query using the url slug. var query = new GetCustomEntityRenderSummaryByIdQuery(); query.CustomEntityId = dbResult.CustomEntityId; query.PublishStatus = PublishStatusQuery.Published; var contentItemDetails = await _customEntityRepository.GetCustomEntityRenderSummaryByIdAsync(query); var model = (ContentDataModel)contentItemDetails.Model; return(new HtmlString(model.Html)); }
private async Task <AuthorDetails> MapAuthor( BlogPostDataModel dataModel, PublishStatusQuery publishStatusQuery ) { if (dataModel.AuthorId < 1) { return(null); } var authorQuery = new GetCustomEntityRenderSummaryByIdQuery(dataModel.AuthorId, publishStatusQuery.ToRelatedEntityQueryStatus()); var dbAuthor = await _customEntityRepository.GetCustomEntityRenderSummaryByIdAsync(authorQuery); var model = dbAuthor?.Model as AuthorDataModel; if (model == null) { return(null); } var author = new AuthorDetails() { Name = dbAuthor.Title, Biography = HtmlFormatter.ConvertToBasicHtml(model.Biography) }; if (model.ProfileImageAssetId < 1) { return(author); } author.ProfileImage = await _imageAssetRepository.GetImageAssetRenderDetailsByIdAsync(model.ProfileImageAssetId.Value); return(author); }
public async Task <FlowerDetails> ExecuteAsync(GetFlowerDetailsByIdQuery query, IExecutionContext executionContext) { var customEntityQuery = new GetCustomEntityRenderSummaryByIdQuery(query.FlowerId); var customEntity = await _customEntityRepository.GetCustomEntityRenderSummaryByIdAsync(customEntityQuery);; if (customEntity == null) { return(null); } return(await MapFlower(customEntity)); }
public async Task <Category> ExecuteAsync(GetCategoryByIdQuery query, IExecutionContext executionContext) { var customEntityQuery = new GetCustomEntityRenderSummaryByIdQuery() { CustomEntityId = query.CategoryId }; var customEntity = await _customEntityRepository.GetCustomEntityRenderSummaryByIdAsync(customEntityQuery);; if (customEntity == null) { return(null); } return(MapCategory(customEntity)); }