2013-08-12 15:06:12 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a base generic ContentPropertyBasic from a Property
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
internal class ContentPropertyBasicConverter<T> : TypeConverter<Property, T>
|
|
|
|
|
|
where T : ContentPropertyBasic, new()
|
|
|
|
|
|
{
|
2013-08-14 19:24:20 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Assigns the PropertyEditor, Id, Alias and Value to the property
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="property"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2013-08-12 15:06:12 +02:00
|
|
|
|
protected override T ConvertCore(Property property)
|
|
|
|
|
|
{
|
|
|
|
|
|
var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId);
|
|
|
|
|
|
if (editor == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO: Remove this check as we shouldn't support this at all!
|
|
|
|
|
|
var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId);
|
|
|
|
|
|
if (legacyEditor == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var legacyResult = new T
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = property.Id,
|
|
|
|
|
|
Value = property.Value == null ? "" : property.Value.ToString(),
|
|
|
|
|
|
Alias = property.Alias
|
|
|
|
|
|
};
|
|
|
|
|
|
return legacyResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
var result = new T
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = property.Id,
|
2013-08-22 18:38:57 +10:00
|
|
|
|
Value = editor.ValueEditor.FormatDataForEditor(property.Value),
|
2013-08-12 15:06:12 +02:00
|
|
|
|
Alias = property.Alias
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result.PropertyEditor = editor;
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-07-25 16:08:18 +10:00
|
|
|
|
}
|