Removing PropertyValues-method from Content and Media and making it an extension method instead.

Adding the PropertyEditor model as internal to slowly adopt it using a slightly different model approach then in v5.
Minor refactoring of IEntity/Entity.
This commit is contained in:
Morten@Thinkpad-X220
2012-10-05 11:03:08 -02:00
parent fe7d57ce12
commit dc1689bdf2
20 changed files with 473 additions and 102 deletions

View File

@@ -278,46 +278,6 @@ namespace Umbraco.Core.Models
}
}
/// <summary>
/// Set property values by alias with an annonymous object
/// </summary>
[IgnoreDataMember]
public object PropertyValues
{
set
{
if (value == null)
throw new Exception("No properties has been passed in");
var propertyInfos = value.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
//Check if a PropertyType with alias exists thus being a valid property
var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (propertyType == null)
throw new Exception(
string.Format(
"The property alias {0} is not valid, because no PropertyType with this alias exists",
propertyInfo.Name));
//Check if a Property with the alias already exists in the collection thus being updated or inserted
var item = Properties.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (item != null)
{
item.Value = propertyInfo.GetValue(value, null);
//Update item with newly added value
Properties.Add(item);
}
else
{
//Create new Property to add to collection
var property = propertyType.CreatePropertyFromValue(propertyInfo.GetValue(value, null));
Properties.Add(property);
}
}
}
}
/// <summary>
/// Collection of properties, which make up all the data available for this Content object
/// </summary>

View File

@@ -0,0 +1,44 @@
using System;
using System.Linq;
namespace Umbraco.Core.Models
{
public static class ContentExtensions
{
/// <summary>
/// Set property values by alias with an annonymous object
/// </summary>
public static void PropertyValues(this IContent content, object value)
{
if (value == null)
throw new Exception("No properties has been passed in");
var propertyInfos = value.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
//Check if a PropertyType with alias exists thus being a valid property
var propertyType = content.PropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (propertyType == null)
throw new Exception(
string.Format(
"The property alias {0} is not valid, because no PropertyType with this alias exists",
propertyInfo.Name));
//Check if a Property with the alias already exists in the collection thus being updated or inserted
var item = content.Properties.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (item != null)
{
item.Value = propertyInfo.GetValue(value, null);
//Update item with newly added value
content.Properties.Add(item);
}
else
{
//Create new Property to add to collection
var property = propertyType.CreatePropertyFromValue(propertyInfo.GetValue(value, null));
content.Properties.Add(property);
}
}
}
}
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Core.Models.EntityBase
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public abstract class Entity : IEntity
public abstract class Entity : IEntity, ICanBeDirty
{
private bool _hasIdentity;
private int? _hash;
@@ -59,13 +59,13 @@ namespace Umbraco.Core.Models.EntityBase
/// Gets or sets the Created Date
/// </summary>
[DataMember]
public DateTime CreatedDate { get; set; }
public DateTime CreateDate { get; set; }
/// <summary>
/// Gets or sets the Modified Date
/// </summary>
[DataMember]
public DateTime ModifiedDate { get; set; }
public DateTime UpdateDate { get; set; }
/// <summary>
/// Property changed event
@@ -91,8 +91,8 @@ namespace Umbraco.Core.Models.EntityBase
/// </summary>
internal virtual void AddingEntity()
{
CreatedDate = DateTime.UtcNow;
ModifiedDate = DateTime.UtcNow;
CreateDate = DateTime.UtcNow;
UpdateDate = DateTime.UtcNow;
}
/// <summary>
@@ -100,7 +100,7 @@ namespace Umbraco.Core.Models.EntityBase
/// </summary>
internal virtual void UpdatingEntity()
{
ModifiedDate = DateTime.UtcNow;
UpdateDate = DateTime.UtcNow;
}
/// <summary>

View File

@@ -29,13 +29,13 @@ namespace Umbraco.Core.Models.EntityBase
/// Gets or sets the Created Date
/// </summary>
[DataMember]
DateTime CreatedDate { get; set; }
DateTime CreateDate { get; set; }
/// <summary>
/// Gets or sets the Modified Date
/// </summary>
[DataMember]
DateTime ModifiedDate { get; set; }
DateTime UpdateDate { get; set; }
/// <summary>
/// Indicates whether the current entity has an identity, eg. Id.

View File

@@ -74,12 +74,6 @@ namespace Umbraco.Core.Models
/// <remarks>PropertyTypes are kind of lazy loaded as part of the object graph</remarks>
IEnumerable<PropertyType> PropertyTypes { get; }
/// <summary>
/// Set property values by alias with an annonymous object
/// </summary>
[IgnoreDataMember]
object PropertyValues { set; }
/// <summary>
/// Indicates whether the content object has a property with the supplied alias
/// </summary>

View File

@@ -185,46 +185,6 @@ namespace Umbraco.Core.Models
}
}
/// <summary>
/// Set property values by alias with an annonymous object
/// </summary>
[IgnoreDataMember]
public object PropertyValues
{
set
{
if (value == null)
throw new Exception("No properties has been passed in");
var propertyInfos = value.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
//Check if a PropertyType with alias exists thus being a valid property
var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (propertyType == null)
throw new Exception(
string.Format(
"The property alias {0} is not valid, because no PropertyType with this alias exists",
propertyInfo.Name));
//Check if a Property with the alias already exists in the collection thus being updated or inserted
var item = Properties.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (item != null)
{
item.Value = propertyInfo.GetValue(value, null);
//Update item with newly added value
Properties.Add(item);
}
else
{
//Create new Property to add to collection
var property = propertyType.CreatePropertyFromValue(propertyInfo.GetValue(value, null));
Properties.Add(property);
}
}
}
}
/// <summary>
/// List of properties, which make up all the data available for this Media object
/// </summary>

View File

@@ -12,7 +12,7 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public class Relation : Entity
{
//NOTE: The datetime column from umbracoRelation is set on CreatedDate on the Entity
//NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity
private int _parentId;
private int _childId;
private RelationType _relationType;