diff --git a/src/Umbraco.Core/Services/IRelationService.cs b/src/Umbraco.Core/Services/IRelationService.cs index cf89ce0540..68a53d1b7f 100644 --- a/src/Umbraco.Core/Services/IRelationService.cs +++ b/src/Umbraco.Core/Services/IRelationService.cs @@ -63,6 +63,21 @@ namespace Umbraco.Core.Services /// An enumerable list of objects IEnumerable GetByParentId(int id); + /// + /// Gets a list of objects by their parent entity + /// + /// Parent Entity to retrieve relations for + /// An enumerable list of objects + IEnumerable GetByParent(IUmbracoEntity parent); + + /// + /// Gets a list of objects by their parent entity + /// + /// Parent Entity to retrieve relations for + /// Alias of the type of relation to retrieve + /// An enumerable list of objects + IEnumerable GetByParent(IUmbracoEntity parent, string relationTypeAlias); + /// /// Gets a list of objects by their child Id /// @@ -70,6 +85,21 @@ namespace Umbraco.Core.Services /// An enumerable list of objects IEnumerable GetByChildId(int id); + /// + /// Gets a list of objects by their child Entity + /// + /// Child Entity to retrieve relations for + /// An enumerable list of objects + IEnumerable GetByChild(IUmbracoEntity child); + + /// + /// Gets a list of objects by their child Entity + /// + /// Child Entity to retrieve relations for + /// Alias of the type of relation to retrieve + /// An enumerable list of objects + IEnumerable GetByChild(IUmbracoEntity child, string relationTypeAlias); + /// /// Gets a list of objects by their child or parent Id. /// Using this method will get you all relations regards of it being a child or parent relation. @@ -190,6 +220,23 @@ namespace Umbraco.Core.Services /// Returns True if any relations exists with the given Ids, otherwise False bool AreRelated(int parentId, int childId); + /// + /// Checks whether two items are related + /// + /// Parent entity + /// Child entity + /// Returns True if any relations exist between the entities, otherwise False + bool AreRelated(IUmbracoEntity parent, IUmbracoEntity child); + + /// + /// Checks whether two items are related + /// + /// Parent entity + /// Child entity + /// Alias of the type of relation to create + /// Returns True if any relations exist between the entities, otherwise False + bool AreRelated(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias); + /// /// Saves a /// diff --git a/src/Umbraco.Core/Services/RelationService.cs b/src/Umbraco.Core/Services/RelationService.cs index 5102731902..bd4a46c75e 100644 --- a/src/Umbraco.Core/Services/RelationService.cs +++ b/src/Umbraco.Core/Services/RelationService.cs @@ -128,6 +128,27 @@ namespace Umbraco.Core.Services } } + /// + /// Gets a list of objects by their parent entity + /// + /// Parent Entity to retrieve relations for + /// An enumerable list of objects + public IEnumerable GetByParent(IUmbracoEntity parent) + { + return GetByParentId(parent.Id); + } + + /// + /// Gets a list of objects by their parent entity + /// + /// Parent Entity to retrieve relations for + /// Alias of the type of relation to retrieve + /// An enumerable list of objects + public IEnumerable GetByParent(IUmbracoEntity parent, string relationTypeAlias) + { + return GetByParent(parent).Where(relation => relation.RelationType.Alias == relationTypeAlias); + } + /// /// Gets a list of objects by their child Id /// @@ -142,6 +163,27 @@ namespace Umbraco.Core.Services } } + /// + /// Gets a list of objects by their child Entity + /// + /// Child Entity to retrieve relations for + /// An enumerable list of objects + public IEnumerable GetByChild(IUmbracoEntity child) + { + return GetByChildId(child.Id); + } + + /// + /// Gets a list of objects by their child Entity + /// + /// Child Entity to retrieve relations for + /// Alias of the type of relation to retrieve + /// An enumerable list of objects + public IEnumerable GetByChild(IUmbracoEntity child, string relationTypeAlias) + { + return GetByChild(child).Where(relation => relation.RelationType.Alias == relationTypeAlias); + } + /// /// Gets a list of objects by their child or parent Id. /// Using this method will get you all relations regards of it being a child or parent relation. @@ -422,7 +464,7 @@ namespace Umbraco.Core.Services public bool AreRelated(int parentId, int childId, string relationTypeAlias) { var relType = GetRelationTypeByAlias(relationTypeAlias); - if(relType == null) + if (relType == null) return false; return AreRelated(parentId, childId, relType); @@ -445,6 +487,29 @@ namespace Umbraco.Core.Services } } + /// + /// Checks whether two items are related + /// + /// Parent entity + /// Child entity + /// Returns True if any relations exist between the entities, otherwise False + public bool AreRelated(IUmbracoEntity parent, IUmbracoEntity child) + { + return AreRelated(parent.Id, child.Id); + } + + /// + /// Checks whether two items are related + /// + /// Parent entity + /// Child entity + /// Alias of the type of relation to create + /// Returns True if any relations exist between the entities, otherwise False + public bool AreRelated(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias) + { + return AreRelated(parent.Id, child.Id, relationTypeAlias); + } + /// /// Saves a