public IEnumerable<PrayerRequest> GetByCategoryIds( List<int> categoryIds, bool onlyApproved = true, bool onlyUnexpired = true )
{
PrayerRequest prayerRequest = new PrayerRequest();
Type type = prayerRequest.GetType();
var prayerRequestEntityTypeId = Rock.Web.Cache.EntityTypeCache.GetId( type );
// Get all PrayerRequest category Ids that are the **parent or child** of the given categoryIds.
CategoryService categoryService = new CategoryService( (RockContext)Context );
IEnumerable<int> expandedCategoryIds = categoryService.GetByEntityTypeId( prayerRequestEntityTypeId )
.Where( c => categoryIds.Contains( c.Id ) || categoryIds.Contains( c.ParentCategoryId ?? -1 ) )
.Select( a => a.Id );
// Now find the active PrayerRequests that have any of those category Ids.
var list = Queryable( "RequestedByPersonAlias.Person" ).Where( p => p.IsActive == true && expandedCategoryIds.Contains( p.CategoryId ?? -1 ) );
if ( onlyApproved )
{
list = list.Where( p => p.IsApproved == true );
}
if ( onlyUnexpired )
{
list = list.Where( p => RockDateTime.Today <= p.ExpirationDate );
}
return list;
}