/// <summary> /// Binds the 'active' categories for the given top-level category GUID to the list for /// the user to choose. /// </summary> /// <param name="categoryGuid">the guid string of a top-level prayer category</param> /// <returns>true if there were active categories or false if there were none</returns> private bool BindCategories( string categoryGuid ) { string settingPrefix = string.Format( "prayer-categories-{0}-", this.BlockId ); IQueryable<PrayerRequest> prayerRequestQuery = new PrayerRequestService( new RockContext() ).GetActiveApprovedUnexpired(); // Filter categories if one has been selected in the configuration if ( !string.IsNullOrEmpty( categoryGuid ) ) { Guid guid = new Guid( categoryGuid ); var filterCategory = CategoryCache.Read( guid ); if ( filterCategory != null ) { prayerRequestQuery = prayerRequestQuery.Where( p => p.Category.ParentCategoryId == filterCategory.Id ); } } var categoryList = prayerRequestQuery .Where( p => p.Category != null ) .Select( p => new { p.Category.Id, p.Category.Name } ) .GroupBy( g => new { g.Id, g.Name } ) .OrderBy( g => g.Key.Name ) .Select( a => new { Id = a.Key.Id, Name = a.Key.Name + " (" + System.Data.Entity.SqlServer.SqlFunctions.StringConvert( (double)a.Count() ).Trim() + ")", Count = a.Count() //,Checked = selectedIDs.Contains( a.Key.Id ) } ).ToList(); cblCategories.DataTextField = "Name"; cblCategories.DataValueField = "Id"; cblCategories.DataSource = categoryList; cblCategories.DataBind(); // use the users preferences to set which items are checked. _savedCategoryIdsSetting = this.GetUserPreference( settingPrefix ).SplitDelimitedValues(); for ( int i = 0; i < cblCategories.Items.Count; i++ ) { ListItem item = (ListItem)cblCategories.Items[i]; item.Selected = _savedCategoryIdsSetting.Contains( item.Value ); } return categoryList.Count() > 0; }