/// <summary> /// Deserialized a module data model to a stongly typed model. /// </summary> /// <param name="typeName">The module type name e.g. 'PlainText', 'RawHtml'.</param> /// <param name="versionModule">The version data to get the serialized model from.</param> /// <returns>Strongly typed data model including deserialized data.</returns> public IPageModuleDataModel MapDataModel(string typeName, IEntityVersionPageModule versionModule) { Type modelType = _moduleDataModelTypeFactory.CreateByPageModuleTypeFileName(typeName); var model = (IPageModuleDataModel)_dbUnstructuredDataSerializer.Deserialize(versionModule.SerializedData, modelType); return(model); }
/// <summary> /// Maps a single page module data model to a concrete /// display model. /// </summary> /// <param name="typeName">The module type name e.g. 'PlainText', 'RawHtml'.</param> /// <param name="versionModule">The version data to get the serialized model from.</param> /// <param name="workflowStatus"> /// The workflow status of the parent page or custom entity /// being mapped. This is provided so dependent entities can use /// the same workflow status. /// </param> /// <returns>Mapped display model.</returns> public IPageModuleDisplayModel MapDisplayModel( string typeName, IEntityVersionPageModule versionModule, WorkFlowStatusQuery workflowStatus ) { return(MapDisplayModel(typeName, new IEntityVersionPageModule[] { versionModule }, workflowStatus) .Select(m => m.DisplayModel) .SingleOrDefault()); }
/// <summary> /// Locates and returns the correct templates for a module if it a custom template /// assigned, otherwise null is returned. /// </summary> /// <param name="pageModule">An unmapped database module to locate the template for.</param> /// <param name="moduleType">The module type associated with the module in which to look for the template.</param> public PageModuleTypeTemplateSummary GetCustomTemplate(IEntityVersionPageModule pageModule, PageModuleTypeSummary moduleType) { Condition.Requires(pageModule, nameof(pageModule)).IsNotNull(); Condition.Requires(pageModule, nameof(moduleType)).IsNotNull(); if (!pageModule.PageModuleTypeTemplateId.HasValue) { return(null); } var template = moduleType .Templates .FirstOrDefault(t => t.PageModuleTypeTemplateId == pageModule.PageModuleTypeTemplateId); Debug.Assert(template != null, string.Format("The module template with id {0} could not be found for {1} {2}", pageModule.PageModuleTypeTemplateId, pageModule.GetType().Name, pageModule.GetVersionModuleId())); return(template); }
public async Task UpdateModelAsync(IPageVersionModuleDataModelCommand command, IEntityVersionPageModule dbModule) { if (command.PageModuleTypeId != dbModule.PageModuleTypeId) { var pageTemplateSectionId = dbModule.PageTemplateSection != null ? dbModule.PageTemplateSection.PageTemplateSectionId : dbModule.PageTemplateSectionId; var pageModuleType = await _dbContext .PageModuleTypes .Where(m => m.PageModuleTypeId == command.PageModuleTypeId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(pageModuleType, command.PageModuleTypeId); dbModule.PageModuleType = pageModuleType; } dbModule.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel); if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId && command.PageModuleTypeTemplateId.HasValue) { dbModule.PageModuleTypeTemplate = await _dbContext .PageModuleTypeTemplates .SingleOrDefaultAsync(m => m.PageModuleTypeId == command.PageModuleTypeId && m.PageModuleTypeTemplateId == command.PageModuleTypeTemplateId); EntityNotFoundException.ThrowIfNull(dbModule.PageModuleTypeTemplate, command.PageModuleTypeTemplateId); } else if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId) { dbModule.PageModuleTypeTemplate = null; } }