diff --git a/src/Umbraco.Core/Models/Relation.cs b/src/Umbraco.Core/Models/Relation.cs new file mode 100644 index 0000000000..f886e3c890 --- /dev/null +++ b/src/Umbraco.Core/Models/Relation.cs @@ -0,0 +1,88 @@ +using System; +using System.Reflection; +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a Relation between two items + /// + [Serializable] + [DataContract(IsReference = true)] + public class Relation : Entity + { + //NOTE: The datetime column from umbracoRelation is set on CreatedDate on the Entity + private int _parentId; + private int _childId; + private RelationType _relationType; + private string _comment; + + public Relation(int parentId, int childId) + { + _parentId = parentId; + _childId = childId; + } + + private static readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); + private static readonly PropertyInfo ChildIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ChildId); + private static readonly PropertyInfo RelationTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.RelationType); + private static readonly PropertyInfo CommentSelector = ExpressionHelper.GetPropertyInfo(x => x.Comment); + + /// + /// Gets or sets the Parent Id of the Relation (Source) + /// + [DataMember] + public int ParentId + { + get { return _parentId; } + set + { + _parentId = value; + OnPropertyChanged(ParentIdSelector); + } + } + + /// + /// Gets or sets the Child Id of the Relation (Destination) + /// + [DataMember] + public int ChildId + { + get { return _childId; } + set + { + _childId = value; + OnPropertyChanged(ChildIdSelector); + } + } + + /// + /// Gets or sets the for the Relation + /// + [DataMember] + public RelationType RelationType + { + get { return _relationType; } + set + { + _relationType = value; + OnPropertyChanged(RelationTypeSelector); + } + } + + /// + /// Gets or sets a comment for the Relation + /// + [DataMember] + public string Comment + { + get { return _comment; } + set + { + _comment = value; + OnPropertyChanged(CommentSelector); + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/RelationType.cs b/src/Umbraco.Core/Models/RelationType.cs new file mode 100644 index 0000000000..38f485e481 --- /dev/null +++ b/src/Umbraco.Core/Models/RelationType.cs @@ -0,0 +1,106 @@ +using System; +using System.Reflection; +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a RelationType + /// + [Serializable] + [DataContract(IsReference = true)] + public class RelationType : Entity + { + private string _name; + private string _alias; + private bool _isBidrectional; + private Guid _parentObjectType; + private Guid _childObjectType; + + public RelationType(Guid childObjectType, Guid parentObjectType, string @alias) + { + _childObjectType = childObjectType; + _parentObjectType = parentObjectType; + _alias = alias; + } + + private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); + private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); + private static readonly PropertyInfo IsBidirectionalSelector = ExpressionHelper.GetPropertyInfo(x => x.IsBidirectional); + private static readonly PropertyInfo ParentObjectTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentObjectType); + private static readonly PropertyInfo ChildObjectTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.ChildObjectType); + + /// + /// Gets or sets the Name of the RelationType + /// + [DataMember] + public string Name + { + get { return _name; } + set + { + _name = value; + OnPropertyChanged(NameSelector); + } + } + + /// + /// Gets or sets the Alias of the RelationType + /// + [DataMember] + public string Alias + { + get { return _alias; } + set + { + _alias = value; + OnPropertyChanged(AliasSelector); + } + } + + /// + /// Gets or sets a boolean indicating whether the RelationType is Bidirectional (true) or Parent to Child (false) + /// + [DataMember] + public bool IsBidirectional + { + get { return _isBidrectional; } + set + { + _isBidrectional = value; + OnPropertyChanged(IsBidirectionalSelector); + } + } + + /// + /// Gets or sets the Parents object type id + /// + /// Corresponds to the NodeObjectType in the umbracoNode table + [DataMember] + public Guid ParentObjectType + { + get { return _parentObjectType; } + set + { + _parentObjectType = value; + OnPropertyChanged(ParentObjectTypeSelector); + } + } + + /// + /// Gets or sets the Childs object type id + /// + /// Corresponds to the NodeObjectType in the umbracoNode table + [DataMember] + public Guid ChildObjectType + { + get { return _childObjectType; } + set + { + _childObjectType = value; + OnPropertyChanged(ChildObjectTypeSelector); + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index fbf011e9c8..4aa5b4e2c9 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -65,6 +65,8 @@ + +