GetByEntityTypeId() public method

Returns a enumerable collection of Rock.Model.Category">Categories by
public GetByEntityTypeId ( int entityTypeId ) : IQueryable
entityTypeId int A representing the EntityTypeId of the to search by.
return IQueryable
Ejemplo n.º 1
0
        /// <summary>
        /// Returns a collection of active <see cref="Rock.Model.PrayerRequest">PrayerRequests</see> that
        /// are in a specified <see cref="Rock.Model.Category"/> or any of its subcategories.
        /// </summary>
        /// <param name="categoryIds">A <see cref="System.Collections.Generic.List{Int32}"/> of
        /// the <see cref="Rock.Model.Category"/> IDs to retrieve PrayerRequests for.</param>
        /// <param name="onlyApproved">set false to include un-approved requests.</param>
        /// <param name="onlyUnexpired">set false to include expired requests.</param>
        /// <returns>An enumerable collection of <see cref="Rock.Model.PrayerRequest"/> that
        /// are in the specified <see cref="Rock.Model.Category"/> or any of its subcategories.</returns>
        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;
        }
        /// <summary>
        /// Returns a collection of active <see cref="Rock.Model.PrayerRequest">PrayerRequests</see> that
        /// are in a specified <see cref="Rock.Model.Category"/> or any of it's subcategories.
        /// </summary>
        /// <param name="categoryIds">A <see cref="System.Collections.Generic.List{Int32}"/> of
        /// the <see cref="Rock.Model.Category"/> IDs to retrieve PrayerRequests for.</param>
        /// <param name="onlyApproved">set false to include un-approved requests.</param>
        /// <param name="onlyUnexpired">set false to include expired requests.</param>
        /// <returns>An enumerable collection of <see cref="Rock.Model.PrayerRequest"/> that
        /// are in the specified <see cref="Rock.Model.Category"/> or any of it's subcategories.</returns>
        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 && categoryIds.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);
        }