Adding AreRelated method to the RelationService

This commit is contained in:
Morten Christensen
2014-01-09 14:12:05 +01:00
parent 72a366d0dc
commit f3f1a161e4
2 changed files with 23 additions and 0 deletions

View File

@@ -182,6 +182,14 @@ namespace Umbraco.Core.Services
/// <returns>Returns <c>True</c> if any relations exists with the given Id, otherwise <c>False</c></returns>
bool IsRelated(int id);
/// <summary>
/// Checks whether two items are related
/// </summary>
/// <param name="parentId">Id of the Parent relation</param>
/// <param name="childId">Id of the Child relation</param>
/// <returns>Returns <c>True</c> if any relations exists with the given Ids, otherwise <c>False</c></returns>
bool AreRelated(int parentId, int childId);
/// <summary>
/// Saves a <see cref="Relation"/>
/// </summary>

View File

@@ -397,6 +397,21 @@ namespace Umbraco.Core.Services
}
}
/// <summary>
/// Checks whether two items are related
/// </summary>
/// <param name="parentId">Id of the Parent relation</param>
/// <param name="childId">Id of the Child relation</param>
/// <returns>Returns <c>True</c> if any relations exists with the given Ids, otherwise <c>False</c></returns>
public bool AreRelated(int parentId, int childId)
{
using (var repository = _repositoryFactory.CreateRelationRepository(_uowProvider.GetUnitOfWork()))
{
var query = new Query<IRelation>().Where(x => x.ParentId == parentId && x.ChildId == childId);
return repository.GetByQuery(query).Any();
}
}
/// <summary>
/// Saves a <see cref="Relation"/>
/// </summary>