private IQueryable<Category> GetUnorderedCategories( RockContext rockContext = null )
        {
            rockContext = rockContext ?? new RockContext();

            string selectedValue = rFilter.GetUserPreference( "EntityType" );

            var attributeEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Attribute ) ).Id;
            var queryable = new CategoryService( rockContext ).Queryable()
                .Where( c =>
                    c.EntityTypeId == attributeEntityTypeId &&
                    c.EntityTypeQualifierColumn == "EntityTypeId" );

            if ( !string.IsNullOrWhiteSpace( selectedValue ) )
            {
                if ( selectedValue == "0" )
                {
                    queryable = queryable.Where( c => c.EntityTypeQualifierValue == null );
                }
                else
                {
                    queryable = queryable.Where( c => c.EntityTypeQualifierValue == selectedValue );
                }
            }
            else
            {
                // Exclude the categories for block and service job attributes, since they are controlled through code attribute decorations
                var exclusions = new List<Guid>();
                exclusions.Add( Rock.SystemGuid.EntityType.BLOCK.AsGuid() );
                exclusions.Add( Rock.SystemGuid.EntityType.SERVICE_JOB.AsGuid() );

                var entities = new EntityTypeService( rockContext ).GetEntities()
                    .Where( t => !exclusions.Contains( t.Guid ) )
                    .Select( e => e.Id )
                    .ToList()
                    .Select( e => e.ToString() )
                    .ToList();

                queryable = queryable.Where( c => entities.Contains( c.EntityTypeQualifierValue ) );
            }

            return queryable;
        }
コード例 #2
0
        private IQueryable<Category> GetUnorderedCategories( int? entityTypeId, RockContext rockContext = null )
        {
            rockContext = rockContext ?? new RockContext();

            var attributeEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Attribute ) ).Id;
            var queryable = new CategoryService( rockContext ).Queryable()
                .Where( c =>
                    c.EntityTypeId == attributeEntityTypeId &&
                    c.EntityTypeQualifierColumn == "EntityTypeId" );

            if ( entityTypeId.HasValue )
            {
                var stringValue = entityTypeId.Value.ToString();
                queryable = queryable.Where( c =>
                    ( entityTypeId.Value == 0 && c.EntityTypeQualifierValue == null ) ||
                    ( entityTypeId.Value != 0 && c.EntityTypeQualifierValue != null && c.EntityTypeQualifierValue == stringValue ) );
            }
            else
            {
                // Exclude the categories for block and service job attributes, since they are controlled through code attribute decorations
                var exclusions = new List<Guid>();
                exclusions.Add( Rock.SystemGuid.EntityType.BLOCK.AsGuid() );
                exclusions.Add( Rock.SystemGuid.EntityType.SERVICE_JOB.AsGuid() );

                var entities = new EntityTypeService( rockContext ).GetEntities()
                    .Where( t => !exclusions.Contains( t.Guid ) )
                    .Select( e => e.Id )
                    .ToList()
                    .Select( e => e.ToString() )
                    .ToList();

                queryable = queryable.Where( c =>
                    c.EntityTypeQualifierValue == null ||
                    entities.Contains( c.EntityTypeQualifierValue ) );
            }

            return queryable;
        }