/// <summary> /// Finds the associated org units. /// </summary> /// <param name="objectContext">The object context.</param> /// <param name="dto">The DTO.</param> /// <returns>An enumerable of the associated Org Unit IDs</returns> public static IEnumerable<int> FindAssociatedOrgUnits(ObjectContext objectContext, AssociatedOrgUnitsDto dto) { List<int> relatedUnits = new List<int>(); var orgUnitAssociationPublished = objectContext.CreateObjectSet<OrgUnitAssociationPublished>(); var orgUnitPublished = objectContext.CreateObjectSet<OrgUnitPublished>(); if (dto.OrganizationalUnitId.HasValue) { var orgUnitIdAsList = new List<int>() { dto.OrganizationalUnitId.Value }; if (dto.DescendantOption != DescendantOption.NoDescendants) { var newUnits = GetDescendants(orgUnitIdAsList, dto.DescendantOption, orgUnitAssociationPublished, orgUnitPublished); AddUnitsToList(ref relatedUnits, newUnits); } if (dto.LinkedOption != LinkedOption.NoLinkedUnits) { var newUnits = GetLinkedUnits(orgUnitIdAsList, dto.LinkedOption, orgUnitAssociationPublished, orgUnitPublished); AddUnitsToList(ref relatedUnits, newUnits); } //add the current org unit AddUnitsToList(ref relatedUnits, new List<int> { dto.OrganizationalUnitId.Value }); } return relatedUnits.ToArray(); }
internal static IEnumerable<int> GetOrgUnitIds(ObjectContext context, int orgUnitId, bool inlcudeDescendants, bool includeLinked) { var ouIds = new List<int> { orgUnitId }; if (inlcudeDescendants || includeLinked) { var aou = new AssociatedOrgUnitsDto { OrganizationalUnitId = orgUnitId }; if (inlcudeDescendants) { if (includeLinked) aou.DescendantOption = DescendantOption.IncludeDescendantsAndTheirLinked; else aou.DescendantOption = DescendantOption.IncludeDescendants; } if (includeLinked) { if (inlcudeDescendants) aou.LinkedOption = LinkedOption.IncludeLinkedUnitsAndTheirDescendants; else aou.LinkedOption = LinkedOption.IncludeLinkedUnits; } ouIds.AddRange(AssociatedOrgUnitFinder.FindAssociatedOrgUnits(context, aou)); } return ouIds; }