Extract methods to retrieve metadata not stored in the model

This commit is contained in:
Tom Fulton
2014-04-24 22:39:22 -06:00
parent fa174ba15a
commit f52bbc2d0a
@@ -38,23 +38,7 @@ namespace Archetype.Umbraco.Extensions
{
// Get list of configured properties and their types and map them to the deserialized archetype model
var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId);
foreach (var fieldset in preValue.Fieldsets)
{
var fieldsetAlias = fieldset.Alias;
foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
{
foreach (var property in fieldset.Properties)
{
var propertyAlias = property.Alias;
foreach (
var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
{
propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
}
}
}
}
RetrieveAdditionalProperties(ref archetype, preValue);
}
catch (Exception ex)
{
@@ -81,14 +65,7 @@ namespace Archetype.Umbraco.Extensions
: preValues.PreValuesAsArray.First().Value;
var config = JsonConvert.DeserializeObject<ArchetypePreValue>(configJson, _jsonSettings);
foreach (var fieldset in config.Fieldsets)
{
foreach (var property in fieldset.Properties)
{
property.PropertyEditorAlias = GetDataTypeByGuid(property.DataTypeGuid).PropertyEditorAlias;
}
}
RetrieveAdditionalProperties(ref config);
return config;
@@ -102,5 +79,46 @@ namespace Archetype.Umbraco.Extensions
() => _app.Services.DataTypeService.GetDataTypeDefinitionById(guid));
}
/// <summary>
/// Retrieves additional metadata that isn't available on the stored model of an Archetype
/// </summary>
/// <param name="archetype">The Archetype to add the additional metadata to</param>
/// <param name="preValue">The configuration of the Archetype</param>
private void RetrieveAdditionalProperties(ref Models.Archetype archetype, ArchetypePreValue preValue)
{
foreach (var fieldset in preValue.Fieldsets)
{
var fieldsetAlias = fieldset.Alias;
foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
{
foreach (var property in fieldset.Properties)
{
var propertyAlias = property.Alias;
foreach ( var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
{
propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
}
}
}
}
}
/// <summary>
/// Retrieves additional metadata that isn't available on the stored model of an ArchetypePreValue
/// </summary>
/// <param name="archetype">The Archetype to add the additional metadata to</param>
/// <param name="preValue">The configuration of the Archetype</param>
private void RetrieveAdditionalProperties(ref Models.ArchetypePreValue preValue)
{
foreach (var fieldset in preValue.Fieldsets)
{
foreach (var property in fieldset.Properties)
{
property.PropertyEditorAlias = GetDataTypeByGuid(property.DataTypeGuid).PropertyEditorAlias;
}
}
}
}
}