using System; using System.Runtime.Serialization; using Umbraco.Cms.Core.Models.Entities; namespace Umbraco.Cms.Core.Models { /// /// Represents a Relation between two items /// [Serializable] [DataContract(IsReference = true)] public class Relation : EntityBase, IRelation { //NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity private int _parentId; private int _childId; private IRelationType _relationType; private string _comment; /// /// Constructor for constructing the entity to be created /// /// /// /// public Relation(int parentId, int childId, IRelationType relationType) { _parentId = parentId; _childId = childId; _relationType = relationType; } /// /// Constructor for reconstructing the entity from the data source /// /// /// /// /// /// public Relation(int parentId, int childId, Guid parentObjectType, Guid childObjectType, IRelationType relationType) { _parentId = parentId; _childId = childId; _relationType = relationType; ParentObjectType = parentObjectType; ChildObjectType = childObjectType; } /// /// Gets or sets the Parent Id of the Relation (Source) /// [DataMember] public int ParentId { get => _parentId; set => SetPropertyValueAndDetectChanges(value, ref _parentId, nameof(ParentId)); } [DataMember] public Guid ParentObjectType { get; set; } /// /// Gets or sets the Child Id of the Relation (Destination) /// [DataMember] public int ChildId { get => _childId; set => SetPropertyValueAndDetectChanges(value, ref _childId, nameof(ChildId)); } [DataMember] public Guid ChildObjectType { get; set; } /// /// Gets or sets the for the Relation /// [DataMember] public IRelationType RelationType { get => _relationType; set => SetPropertyValueAndDetectChanges(value, ref _relationType, nameof(RelationType)); } /// /// Gets or sets a comment for the Relation /// [DataMember] public string Comment { get => _comment; set => SetPropertyValueAndDetectChanges(value, ref _comment, nameof(Comment)); } /// /// Gets the Id of the that this Relation is based on. /// [IgnoreDataMember] public int RelationTypeId => _relationType.Id; } }