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, IAggregateRoot
{
//NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity
private int _parentId;
private int _childId;
private RelationType _relationType;
private string _comment;
public Relation(int parentId, int childId, RelationType relationType)
{
_parentId = parentId;
_childId = childId;
_relationType = relationType;
}
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);
}
}
///
/// Gets the Id of the that this Relation is based on.
///
[IgnoreDataMember]
public int RelationTypeId
{
get { return _relationType.Id; }
}
}
}