Adds Relation and RelationType U4-932
This commit is contained in:
88
src/Umbraco.Core/Models/Relation.cs
Normal file
88
src/Umbraco.Core/Models/Relation.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Relation between two items
|
||||
/// </summary>
|
||||
[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<Relation, int>(x => x.ParentId);
|
||||
private static readonly PropertyInfo ChildIdSelector = ExpressionHelper.GetPropertyInfo<Relation, int>(x => x.ChildId);
|
||||
private static readonly PropertyInfo RelationTypeSelector = ExpressionHelper.GetPropertyInfo<Relation, RelationType>(x => x.RelationType);
|
||||
private static readonly PropertyInfo CommentSelector = ExpressionHelper.GetPropertyInfo<Relation, string>(x => x.Comment);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Parent Id of the Relation (Source)
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int ParentId
|
||||
{
|
||||
get { return _parentId; }
|
||||
set
|
||||
{
|
||||
_parentId = value;
|
||||
OnPropertyChanged(ParentIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Child Id of the Relation (Destination)
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int ChildId
|
||||
{
|
||||
get { return _childId; }
|
||||
set
|
||||
{
|
||||
_childId = value;
|
||||
OnPropertyChanged(ChildIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="RelationType"/> for the Relation
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public RelationType RelationType
|
||||
{
|
||||
get { return _relationType; }
|
||||
set
|
||||
{
|
||||
_relationType = value;
|
||||
OnPropertyChanged(RelationTypeSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a comment for the Relation
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Comment
|
||||
{
|
||||
get { return _comment; }
|
||||
set
|
||||
{
|
||||
_comment = value;
|
||||
OnPropertyChanged(CommentSelector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
106
src/Umbraco.Core/Models/RelationType.cs
Normal file
106
src/Umbraco.Core/Models/RelationType.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a RelationType
|
||||
/// </summary>
|
||||
[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<RelationType, string>(x => x.Name);
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<RelationType, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo IsBidirectionalSelector = ExpressionHelper.GetPropertyInfo<RelationType, bool>(x => x.IsBidirectional);
|
||||
private static readonly PropertyInfo ParentObjectTypeSelector = ExpressionHelper.GetPropertyInfo<RelationType, Guid>(x => x.ParentObjectType);
|
||||
private static readonly PropertyInfo ChildObjectTypeSelector = ExpressionHelper.GetPropertyInfo<RelationType, Guid>(x => x.ChildObjectType);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name of the RelationType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
OnPropertyChanged(NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Alias of the RelationType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set
|
||||
{
|
||||
_alias = value;
|
||||
OnPropertyChanged(AliasSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the RelationType is Bidirectional (true) or Parent to Child (false)
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool IsBidirectional
|
||||
{
|
||||
get { return _isBidrectional; }
|
||||
set
|
||||
{
|
||||
_isBidrectional = value;
|
||||
OnPropertyChanged(IsBidirectionalSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Parents object type id
|
||||
/// </summary>
|
||||
/// <remarks>Corresponds to the NodeObjectType in the umbracoNode table</remarks>
|
||||
[DataMember]
|
||||
public Guid ParentObjectType
|
||||
{
|
||||
get { return _parentObjectType; }
|
||||
set
|
||||
{
|
||||
_parentObjectType = value;
|
||||
OnPropertyChanged(ParentObjectTypeSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Childs object type id
|
||||
/// </summary>
|
||||
/// <remarks>Corresponds to the NodeObjectType in the umbracoNode table</remarks>
|
||||
[DataMember]
|
||||
public Guid ChildObjectType
|
||||
{
|
||||
get { return _childObjectType; }
|
||||
set
|
||||
{
|
||||
_childObjectType = value;
|
||||
OnPropertyChanged(ChildObjectTypeSelector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,8 @@
|
||||
<Compile Include="Models\DictionaryItem.cs" />
|
||||
<Compile Include="Models\DictionaryTranslation.cs" />
|
||||
<Compile Include="Models\Language.cs" />
|
||||
<Compile Include="Models\Relation.cs" />
|
||||
<Compile Include="Models\RelationType.cs" />
|
||||
<Compile Include="PublishedContentExtensions.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionary.cs" />
|
||||
<Compile Include="Dynamics\ClassFactory.cs" />
|
||||
|
||||
Reference in New Issue
Block a user