/// <summary> /// Loads the groups. /// </summary> private void LoadDropDowns() { var parts = ( GetAttributeValue( "GroupFilter" ) ?? string.Empty ).Split( '|' ); Guid? groupTypeGuid = null; Guid? rootGroupGuid = null; if ( parts.Length >= 1 ) { groupTypeGuid = parts[0].AsGuidOrNull(); if ( parts.Length >= 2 ) { rootGroupGuid = parts[1].AsGuidOrNull(); } } var groupService = new GroupService( new RockContext() ); string defaultGroupPublicKey = string.Empty; var contextCookie = Request.Cookies["Rock:context"]; if ( contextCookie != null ) { var cookieValue = contextCookie.Values[typeof( Rock.Model.Group ).FullName]; string contextItem = Rock.Security.Encryption.DecryptString( cookieValue ); string[] contextItemParts = contextItem.Split( '|' ); if ( contextItemParts.Length == 2 ) { defaultGroupPublicKey = contextItemParts[1]; } } var defaultGroup = groupService.GetByPublicKey( defaultGroupPublicKey ); IQueryable<Group> qryGroups = null; // if rootGroup is set, use that as the filter. Otherwise, use GroupType as the filter if ( rootGroupGuid.HasValue ) { var rootGroup = groupService.Get( rootGroupGuid.Value ); if ( rootGroup != null ) { qryGroups = groupService.GetAllDescendents( rootGroup.Id ).AsQueryable(); } } else if ( groupTypeGuid.HasValue ) { qryGroups = groupService.Queryable().Where( a => a.GroupType.Guid == groupTypeGuid.Value ); } if ( qryGroups == null ) { nbSelectGroupTypeWarning.Visible = true; ddlGroup.Visible = false; } else { nbSelectGroupTypeWarning.Visible = false; ddlGroup.Visible = true; ddlGroup.Items.Clear(); var groups = qryGroups.OrderBy( a => a.Order ).ThenBy( a => a.Name ).ToList(); foreach ( var group in groups ) { var listItem = new ListItem( group.Name, HttpUtility.UrlDecode( group.ContextKey ) ); if ( defaultGroup != null ) { listItem.Selected = group.Guid == defaultGroup.Guid; } ddlGroup.Items.Add( listItem ); } } }