/// <summary> /// Gets the navigation children. /// </summary> /// <param name="parentCategoryId">The parent category identifier.</param> /// <param name="categories">The categories.</param> /// <param name="selectedCategoryGuids">The selected category guids.</param> /// <param name="checkSelected">if set to <c>true</c> [check selected].</param> /// <param name="includeAllChildren">if set to <c>true</c> [include all children].</param> /// <param name="currentPerson">The current person.</param> /// <returns></returns> private List <CategoryNavigationItem> GetNavigationChildren(int?parentCategoryId, IEnumerable <Category> categories, List <Guid> selectedCategoryGuids, bool checkSelected, bool includeAllChildren, Person currentPerson) { var items = new List <CategoryNavigationItem>(); foreach (var category in categories .Where(c => c.ParentCategoryId == parentCategoryId || (!c.ParentCategoryId.HasValue && !parentCategoryId.HasValue)) .OrderBy(c => c.Order) .ThenBy(c => c.Name)) { if (category.IsAuthorized(Rock.Security.Authorization.VIEW, currentPerson)) { bool includeCategory = !checkSelected || selectedCategoryGuids.Contains(category.Guid); bool checkChildSelected = checkSelected; if (includeCategory) { if (checkSelected && includeAllChildren) { checkChildSelected = false; } var categoryItem = new CategoryNavigationItem(category); items.Add(categoryItem); // Recurse child categories categoryItem.ChildCategories = GetNavigationChildren(category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson); } else { foreach (var categoryItem in GetNavigationChildren(category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson)) { items.Add(categoryItem); } } } } return(items); }
/// <summary> /// Gets the navigation children. /// </summary> /// <param name="parentCategoryId">The parent category identifier.</param> /// <param name="categories">The categories.</param> /// <param name="selectedCategoryGuids">The selected category guids.</param> /// <param name="checkSelected">if set to <c>true</c> [check selected].</param> /// <param name="includeAllChildren">if set to <c>true</c> [include all children].</param> /// <param name="currentPerson">The current person.</param> /// <returns></returns> private List<CategoryNavigationItem> GetNavigationChildren( int? parentCategoryId, IEnumerable<Category> categories, List<Guid> selectedCategoryGuids, bool checkSelected, bool includeAllChildren, Person currentPerson ) { var items = new List<CategoryNavigationItem>(); foreach ( var category in categories .Where( c => c.ParentCategoryId == parentCategoryId || ( !c.ParentCategoryId.HasValue && !parentCategoryId.HasValue ) ) .OrderBy( c => c.Order ) .ThenBy( c => c.Name ) ) { if ( category.IsAuthorized( Rock.Security.Authorization.VIEW, currentPerson ) ) { bool includeCategory = !checkSelected || selectedCategoryGuids.Contains( category.Guid ); bool checkChildSelected = checkSelected; if ( includeCategory ) { if ( checkSelected && includeAllChildren ) { checkChildSelected = false; } var categoryItem = new CategoryNavigationItem( category ); items.Add( categoryItem ); // Recurse child categories categoryItem.ChildCategories = GetNavigationChildren( category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson ); } else { foreach ( var categoryItem in GetNavigationChildren( category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson ) ) { items.Add( categoryItem ); } } } } return items; }