private CustomEntityDetails MapInitialData(CustomEntityVersion dbVersion, IExecutionContext executionContext) { var entity = new CustomEntityDetails() { CustomEntityId = dbVersion.CustomEntity.CustomEntityId, UrlSlug = dbVersion.CustomEntity.UrlSlug, PublishStatus = PublishStatusMapper.FromCode(dbVersion.CustomEntity.PublishStatusCode), PublishDate = DbDateTimeMapper.AsUtc(dbVersion.CustomEntity.PublishDate), }; entity.IsPublished = entity.PublishStatus == PublishStatus.Published && entity.PublishDate <= executionContext.ExecutionDate; entity.AuditData = _auditDataMapper.MapCreateAuditData(dbVersion.CustomEntity); entity.LatestVersion = new CustomEntityVersionDetails() { CustomEntityVersionId = dbVersion.CustomEntityVersionId, Title = dbVersion.Title, WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId }; entity.LatestVersion.AuditData = _auditDataMapper.MapCreateAuditData(dbVersion); entity.HasDraft = entity.LatestVersion.WorkFlowStatus == WorkFlowStatus.Draft; return(entity); }
/// <summary> /// Maps an EF PageTemplate record from the db into an PageTemplateDetailsMapper /// object. If the db record is null then null is returned. /// </summary> /// <param name="queryModel">Query data returned from the database.</param> public PageTemplateDetails Map(PageTemplateDetailsQueryModel queryModel) { var dbPageTemplate = queryModel?.PageTemplate; if (dbPageTemplate == null) { return(null); } var pageTemplate = new PageTemplateDetails() { FullPath = dbPageTemplate.FullPath, IsArchived = dbPageTemplate.IsArchived, Name = dbPageTemplate.Name, PageTemplateId = dbPageTemplate.PageTemplateId, CreateDate = DbDateTimeMapper.AsUtc(dbPageTemplate.CreateDate), Description = dbPageTemplate.Description, FileName = dbPageTemplate.FileName, PageType = (PageType)dbPageTemplate.PageTypeId, CustomEntityModelType = dbPageTemplate.CustomEntityModelType, UpdateDate = DbDateTimeMapper.AsUtc(dbPageTemplate.UpdateDate), NumPages = queryModel.NumPages, CustomEntityDefinition = queryModel.CustomEntityDefinition }; pageTemplate.Regions = queryModel .PageTemplate .PageTemplateRegions .Select(MapRegion) .ToList(); return(pageTemplate); }
/// <summary> /// Maps an EF PageTemplate record from the db into an PageTemplateSummary /// object. If the db record is null then null is returned. /// </summary> /// <param name="queryModel">Query model with data from the database.</param> public PageTemplateSummary Map(PageTemplateSummaryQueryModel queryModel) { var dbPageTemplate = queryModel?.PageTemplate; if (dbPageTemplate == null) { return(null); } var pageTemplate = new PageTemplateSummary() { IsArchived = dbPageTemplate.IsArchived, Name = dbPageTemplate.Name, PageTemplateId = dbPageTemplate.PageTemplateId, CreateDate = DbDateTimeMapper.AsUtc(dbPageTemplate.CreateDate), Description = dbPageTemplate.Description, FileName = dbPageTemplate.FileName, PageType = (PageType)dbPageTemplate.PageTypeId, UpdateDate = DbDateTimeMapper.AsUtc(dbPageTemplate.UpdateDate), NumPages = queryModel.NumPages, NumRegions = queryModel.NumRegions }; return(pageTemplate); }
/// <summary> /// Maps an EF CustomEntity record from the db into a CustomEntityRoute object. If the /// db record is null then null is returned. /// </summary> /// <param name="dbCustomEntity">CustomEntity record from the database.</param> /// <param name="locale">Locale to map to the object.</param> public CustomEntityRoute Map( CustomEntity dbCustomEntity, ActiveLocale locale ) { if (dbCustomEntity == null) { throw new ArgumentNullException(nameof(dbCustomEntity)); } if (dbCustomEntity.CustomEntityVersions == null) { throw new ArgumentNullException(nameof(dbCustomEntity.CustomEntityVersions)); } var route = new CustomEntityRoute() { CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbCustomEntity.CustomEntityId, UrlSlug = dbCustomEntity.UrlSlug, Locale = locale, PublishDate = DbDateTimeMapper.AsUtc(dbCustomEntity.PublishDate), PublishStatus = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished, Ordering = dbCustomEntity.Ordering }; bool hasLatestPublishVersion = false; route.Versions = new List <CustomEntityVersionRoute>(); foreach (var dbVersion in dbCustomEntity .CustomEntityVersions .OrderByLatest()) { var version = new CustomEntityVersionRoute() { CreateDate = DbDateTimeMapper.AsUtc(dbVersion.CreateDate), Title = dbVersion.Title, VersionId = dbVersion.CustomEntityVersionId, WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId }; if (!hasLatestPublishVersion && version.WorkFlowStatus == WorkFlowStatus.Published) { version.IsLatestPublishedVersion = true; hasLatestPublishVersion = true; } route.Versions.Add(version); } route.HasDraftVersion = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Draft); route.HasPublishedVersion = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Published); return(route); }
/// <summary> /// Updates an UpdateAuditData object using the creator information from the model as the updater /// information. Useful when you are mapping audit information from two different objects. If the /// db record is null then an ArgumentNullException is thrown. /// </summary> /// <param name="model">ICreateAuditable EF database record to map create data from.</param> public void MapUpdateAuditDataUpdaterData(UpdateAuditData updateAuditDatra, ICreateAuditable model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ValidateUserProperty(model.Creator, nameof(model.Creator)); updateAuditDatra.UpdateDate = DbDateTimeMapper.AsUtc(model.CreateDate); updateAuditDatra.Updater = _userMicroSummaryMapper.Map(model.Creator); }
private PageTemplateRegionDetails MapRegion(PageTemplateRegion dbRegion) { return(new PageTemplateRegionDetails() { CreateDate = DbDateTimeMapper.AsUtc(dbRegion.CreateDate), IsCustomEntityRegion = dbRegion.IsCustomEntityRegion, Name = dbRegion.Name, PageTemplateId = dbRegion.PageTemplateId, PageTemplateRegionId = dbRegion.PageTemplateRegionId, UpdateDate = DbDateTimeMapper.AsUtc(dbRegion.UpdateDate) }); }
/// <summary> /// Maps an EF model that inherits from ICreateAuditable into a UpdateAuditData object /// using only the creator information from the model. Useful when you are mapping audit /// information from two different objects. If the db record is null then an ArgumentNullException is thrown. /// </summary> /// <param name="model">ICreateAuditable EF database record to map create data from.</param> public UpdateAuditData MapUpdateAuditDataCreatorData(ICreateAuditable model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ValidateUserProperty(model.Creator, nameof(model.Creator)); var auditData = new UpdateAuditData(); auditData.CreateDate = DbDateTimeMapper.AsUtc(model.CreateDate); auditData.Creator = _userMicroSummaryMapper.Map(model.Creator); return(auditData); }
/// <summary> /// Maps an EF DocumentAsset record from the db into a DocumentAssetDetails /// object. If the db record is null then null is returned. /// </summary> /// <param name="dbDocument">DocumentAsset record from the database.</param> public DocumentAssetDetails Map(DocumentAsset dbDocument) { if (dbDocument == null) { return(null); } var document = new DocumentAssetDetails(); _documentAssetSummaryMapper.Map(document, dbDocument); document.Description = dbDocument.Description; document.FileUpdateDate = DbDateTimeMapper.AsUtc(dbDocument.FileUpdateDate); return(document); }
/// <summary> /// Maps an EF user record from the db into a UserDetails object. If the /// db record is null then null is returned. /// </summary> /// <param name="dbUser">User record from the database.</param> public UserDetails Map(User dbUser) { if (dbUser == null) { return(null); } if (dbUser.Role == null) { throw new ArgumentException("dbUser.Role must be included in the query to map to use the UserDetailsMapper"); } var user = new UserDetails() { Email = dbUser.Email, FirstName = dbUser.FirstName, LastName = dbUser.LastName, UserId = dbUser.UserId, Username = dbUser.Username, LastLoginDate = DbDateTimeMapper.AsUtc(dbUser.LastLoginDate), LastPasswordChangeDate = DbDateTimeMapper.AsUtc(dbUser.LastPasswordChangeDate), RequirePasswordChange = dbUser.RequirePasswordChange }; user.AuditData = new CreateAuditData() { CreateDate = DbDateTimeMapper.AsUtc(dbUser.CreateDate) }; if (dbUser.Creator != null) { user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator); } var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode); EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode); user.UserArea = new UserAreaMicroSummary() { UserAreaCode = dbUser.UserAreaCode, Name = userArea.Name }; user.Role = _roleDetailsMapper.Map(dbUser.Role); return(user); }
/// <summary> /// Maps an EF user record from the db into a UserAccountDetails object. If the /// db record is null then null is returned. /// </summary> /// <param name="dbUser">User record from the database.</param> public UserAccountDetails Map(User dbUser) { if (dbUser == null) { return(null); } var user = new UserAccountDetails() { Email = dbUser.Email, FirstName = dbUser.FirstName, LastName = dbUser.LastName, UserId = dbUser.UserId, Username = dbUser.Username, LastLoginDate = DbDateTimeMapper.AsUtc(dbUser.LastLoginDate), LastPasswordChangeDate = DbDateTimeMapper.AsUtc(dbUser.LastPasswordChangeDate), PreviousLoginDate = DbDateTimeMapper.AsUtc(dbUser.PreviousLoginDate), RequirePasswordChange = dbUser.RequirePasswordChange }; user.AuditData = new CreateAuditData() { CreateDate = DbDateTimeMapper.AsUtc(dbUser.CreateDate) }; if (dbUser.Creator != null) { user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator); } var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode); EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode); user.UserArea = new UserAreaMicroSummary() { UserAreaCode = dbUser.UserAreaCode, Name = userArea.Name }; return(user); }
/// <summary> /// Maps an EF ImageAsset record from the db into a ImageAssetDetails /// object. If the db record is null then null is returned. /// </summary> /// <param name="dbImage">ImageAsset record from the database.</param> public ImageAssetRenderDetails Map(ImageAsset dbImage) { if (dbImage == null) { return(null); } var image = new ImageAssetRenderDetails(); image.ImageAssetId = dbImage.ImageAssetId; image.Extension = dbImage.Extension; image.FileName = dbImage.FileName; image.Height = dbImage.Height; image.Width = dbImage.Width; image.Title = dbImage.FileDescription; image.DefaultAnchorLocation = dbImage.DefaultAnchorLocation; image.UpdateDate = DbDateTimeMapper.AsUtc(dbImage.UpdateDate); return(image); }
private CustomEntityRenderSummary MapCore(CustomEntityVersion dbResult) { var entity = new CustomEntityRenderSummary() { CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate), CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbResult.CustomEntityId, CustomEntityVersionId = dbResult.CustomEntityVersionId, Ordering = dbResult.CustomEntity.Ordering, Title = dbResult.Title, UrlSlug = dbResult.CustomEntity.UrlSlug, WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId, PublishDate = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate) }; entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode); entity.Model = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData); return(entity); }
private CustomEntitySummary MapBasicProperties(CustomEntityPublishStatusQuery dbStatusQuery) { var entity = new CustomEntitySummary() { AuditData = _auditDataMapper.MapUpdateAuditDataCreatorData(dbStatusQuery.CustomEntity), CustomEntityDefinitionCode = dbStatusQuery.CustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbStatusQuery.CustomEntityId, HasDraftVersion = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Draft, // note that if this is not a published version, we do further checks on this later in the process HasPublishedVersion = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Published, PublishStatus = PublishStatusMapper.FromCode(dbStatusQuery.CustomEntity.PublishStatusCode), PublishDate = DbDateTimeMapper.AsUtc(dbStatusQuery.CustomEntity.PublishDate), Ordering = dbStatusQuery.CustomEntity.Ordering, Title = dbStatusQuery.CustomEntityVersion.Title, UrlSlug = dbStatusQuery.CustomEntity.UrlSlug }; _auditDataMapper.MapUpdateAuditDataUpdaterData(entity.AuditData, dbStatusQuery.CustomEntityVersion); return(entity); }
private CustomEntityRenderDetails MapCustomEntity(CustomEntityVersion dbResult, IExecutionContext executionContext) { _permissionValidationService.EnforceCustomEntityPermission <CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext); var entity = new CustomEntityRenderDetails() { CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate), CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbResult.CustomEntityId, CustomEntityVersionId = dbResult.CustomEntityVersionId, Ordering = dbResult.CustomEntity.Ordering, Title = dbResult.Title, UrlSlug = dbResult.CustomEntity.UrlSlug, WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId, PublishDate = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate) }; entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode); entity.Model = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData); return(entity); }
private async Task<CustomEntityRenderDetails> MapCustomEntityAsync(CustomEntityVersion dbResult) { await _permissionValidationService.EnforceCustomEntityPermissionAsync<CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode); var entity = new CustomEntityRenderDetails() { CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate), CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbResult.CustomEntityId, CustomEntityVersionId = dbResult.CustomEntityVersionId, Ordering = dbResult.CustomEntity.Ordering, Title = dbResult.Title, UrlSlug = dbResult.CustomEntity.UrlSlug, WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId, PublishDate = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate) }; entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode); entity.Model = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData); return entity; }
/// <summary> /// Maps an EF CustomEntity record from the db into a CustomEntityRoute object. If the /// db record is null then null is returned. /// </summary> /// <param name="dbCustomEntity">CustomEntity record from the database.</param> /// <param name="locale">Locale to map to the object.</param> /// <param name="routingDataProperties">Collection of data properties to map to the routing parameters collection.</param> public CustomEntityRoute Map( CustomEntity dbCustomEntity, ActiveLocale locale ) { if (dbCustomEntity == null) { throw new ArgumentNullException(nameof(dbCustomEntity)); } var route = new CustomEntityRoute() { CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbCustomEntity.CustomEntityId, UrlSlug = dbCustomEntity.UrlSlug, Locale = locale, PublishDate = DbDateTimeMapper.AsUtc(dbCustomEntity.PublishDate), PublishStatus = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished, Ordering = dbCustomEntity.Ordering }; var versions = new List <CustomEntityVersionRoute>(); route.Versions = versions; foreach (var dbVersion in dbCustomEntity.CustomEntityVersions) { var version = new CustomEntityVersionRoute() { CreateDate = DbDateTimeMapper.AsUtc(dbVersion.CreateDate), Title = dbVersion.Title, VersionId = dbVersion.CustomEntityVersionId, WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId }; versions.Add(version); } return(route); }
private IQueryable <PageQueryResult> QueryPages() { var dbPages = _dbContext .Pages .AsNoTracking() .FilterActive() .Select(p => new PageQueryResult() { RoutingInfo = new PageRoute() { PageId = p.PageId, UrlPath = p.UrlPath, PageType = (PageType)p.PageTypeId, CustomEntityDefinitionCode = p.CustomEntityDefinitionCode, PublishDate = DbDateTimeMapper.AsUtc(p.PublishDate), PublishStatus = PublishStatusMapper.FromCode(p.PublishStatusCode) }, LocaleId = p.LocaleId, PageDirectoryId = p.PageDirectoryId }); return(dbPages); }
private PageVersionRoute MapVersion( PageRoute routingInfo, PageVersionQueryResult version, Dictionary <int, PageTemplateQueryResult> templates ) { var versionRouting = new PageVersionRoute(); versionRouting.WorkFlowStatus = (WorkFlowStatus)version.WorkFlowStatusId; versionRouting.Title = version.Title; versionRouting.CreateDate = DbDateTimeMapper.AsUtc(version.CreateDate); versionRouting.VersionId = version.PageVersionId; var template = templates.GetOrDefault(version.PageTemplateId); if (template != null) { versionRouting.PageTemplateId = version.PageTemplateId; versionRouting.HasCustomEntityRegions = template.HasCustomEntityRegions; versionRouting.HasPageRegions = template.HasPageRegions; } return(versionRouting); }
/// <summary> /// Maps a collection of EF CustomEntityVersion records from the db into CustomEntitySummary /// objects. /// </summary> /// <param name="dbStatusQueries">Collection of versions to map.</param> public async Task <List <CustomEntitySummary> > MapAsync(ICollection <CustomEntityPublishStatusQuery> dbStatusQueries, IExecutionContext executionContext) { var entities = new List <CustomEntitySummary>(dbStatusQueries.Count); var routingsQuery = new GetPageRoutingInfoByCustomEntityIdRangeQuery(dbStatusQueries.Select(e => e.CustomEntityId)); var routings = await _queryExecutor.ExecuteAsync(routingsQuery, executionContext); Dictionary <int, ActiveLocale> allLocales = null; Dictionary <string, CustomEntityDefinitionSummary> customEntityDefinitions = new Dictionary <string, CustomEntityDefinitionSummary>(); var hasCheckedQueryValid = false; foreach (var dbStatusQuery in dbStatusQueries) { // Validate the input data if (!hasCheckedQueryValid) { ValidateQuery(dbStatusQuery); } hasCheckedQueryValid = true; // Easy mappings var entity = new CustomEntitySummary() { AuditData = _auditDataMapper.MapUpdateAuditDataCreatorData(dbStatusQuery.CustomEntity), CustomEntityDefinitionCode = dbStatusQuery.CustomEntity.CustomEntityDefinitionCode, CustomEntityId = dbStatusQuery.CustomEntityId, HasDraft = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Draft, PublishStatus = PublishStatusMapper.FromCode(dbStatusQuery.CustomEntity.PublishStatusCode), PublishDate = DbDateTimeMapper.AsUtc(dbStatusQuery.CustomEntity.PublishDate), Ordering = dbStatusQuery.CustomEntity.Ordering, Title = dbStatusQuery.CustomEntityVersion.Title, UrlSlug = dbStatusQuery.CustomEntity.UrlSlug }; entity.IsPublished = entity.PublishStatus == PublishStatus.Published && entity.PublishDate <= executionContext.ExecutionDate; _auditDataMapper.MapUpdateAuditDataUpdaterData(entity.AuditData, dbStatusQuery.CustomEntityVersion); // Routing data (if any) PageRoutingInfo detailsRouting = null; if (routings.ContainsKey(dbStatusQuery.CustomEntityId)) { detailsRouting = routings[dbStatusQuery.CustomEntityId].FirstOrDefault(r => r.CustomEntityRouteRule != null); entity.FullPath = detailsRouting?.CustomEntityRouteRule?.MakeUrl(detailsRouting.PageRoute, detailsRouting.CustomEntityRoute); } // Locale data var localeId = dbStatusQuery.CustomEntity.LocaleId; if (localeId.HasValue && detailsRouting != null) { entity.Locale = detailsRouting.PageRoute.Locale; EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value); } else if (localeId.HasValue) { // Lazy load locales, since they aren't always used if (allLocales == null) { allLocales = await GetLocalesAsync(executionContext); } entity.Locale = allLocales.GetOrDefault(localeId.Value); EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value); } // Parse model data var definition = customEntityDefinitions.GetOrDefault(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode); if (definition == null) { // Load and cache definitions var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode); definition = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext); EntityNotFoundException.ThrowIfNull(definition, definition.CustomEntityDefinitionCode); customEntityDefinitions.Add(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode, definition); } entity.Model = (ICustomEntityDataModel)_dbUnstructuredDataSerializer.Deserialize(dbStatusQuery.CustomEntityVersion.SerializedData, definition.DataModelType); entities.Add(entity); } return(entities); }