예제 #1
0
        protected void rGridAttribute_Bind(string typeId)
        {
            var queryable = attributeService.Queryable().
                            Where(a => a.Entity == entity &&
                                  (a.EntityQualifierColumn ?? string.Empty) == entityQualifierColumn &&
                                  (a.EntityQualifierValue ?? string.Empty) == typeId);

            rGridAttribute.DataSource = queryable.
                                        OrderBy(a => a.Category).
                                        ThenBy(a => a.Key).
                                        ToList();

            rGridAttribute.DataBind();
        }
예제 #2
0
        private void BindGrid()
        {
            var queryable = _attributeService.Queryable().
                            Where(a => a.Entity == _entity &&
                                  (a.EntityQualifierColumn ?? string.Empty) == _entityQualifierColumn &&
                                  (a.EntityQualifierValue ?? string.Empty) == _entityQualifierValue);

            if (ddlCategoryFilter.SelectedValue != "[All]")
            {
                queryable = queryable.
                            Where(a => a.Category == ddlCategoryFilter.SelectedValue);
            }

            rGrid.DataSource = queryable.
                               OrderBy(a => a.Category).
                               ThenBy(a => a.Key).
                               ToList();

            rGrid.DataBind();
        }
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            string entity = AttributeValue( "Entity" );
            if ( string.IsNullOrWhiteSpace( entity ) )
                entity = PageParameter( "Entity" );

            string entityQualifierColumn = AttributeValue( "EntityQualifierColumn" );
            if ( string.IsNullOrWhiteSpace( entityQualifierColumn ) )
                entityQualifierColumn = PageParameter( "EntityQualifierColumn" );

            string entityQualifierValue = AttributeValue( "EntityQualifierValue" );
            if ( string.IsNullOrWhiteSpace( entityQualifierValue ) )
                entityQualifierValue = PageParameter( "EntityQualifierValue" );

            _category = AttributeValue( "AttributeCategory" );
            if ( string.IsNullOrWhiteSpace( _category ) )
                _category = PageParameter( "AttributeCategory" );

            ObjectCache cache = MemoryCache.Default;
            string cacheKey = string.Format( "Attributes:{0}:{1}:{2}", entity, entityQualifierColumn, entityQualifierValue );

            Dictionary<string, List<int>> cachedAttributes = cache[cacheKey] as Dictionary<string, List<int>>;
            if ( cachedAttributes == null )
            {
                cachedAttributes = new Dictionary<string, List<int>>();

                AttributeService attributeService = new AttributeService();
                foreach ( var item in attributeService.Queryable().
                    Where( a => a.Entity == entity &&
                        ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn &&
                        ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue ).
                    OrderBy( a => a.Category ).
                    ThenBy( a => a.Order ).
                    Select( a => new { a.Category, a.Id } ) )
                {
                    if ( !cachedAttributes.ContainsKey( item.Category ) )
                        cachedAttributes.Add( item.Category, new List<int>() );
                    cachedAttributes[item.Category].Add( item.Id );
                }

                CacheItemPolicy cacheItemPolicy = null;
                cache.Set( cacheKey, cachedAttributes, cacheItemPolicy );
            }

            Rock.Attribute.IHasAttributes model = PageInstance.GetCurrentContext( entity ) as Rock.Attribute.IHasAttributes;
            if ( model != null )
            {
                if ( cachedAttributes.ContainsKey( _category ) )
                    foreach ( var attributeId in cachedAttributes[_category] )
                    {
                        var attribute = Rock.Web.Cache.Attribute.Read( attributeId );
                        if ( attribute != null )
                            phAttributes.Controls.Add( ( AttributeInstanceValues )this.LoadControl( "~/Blocks/Core/AttributeInstanceValues.ascx", model, attribute, CurrentPersonId ) );
                    }
            }

            string script = @"
            Sys.Application.add_load(function () {
            $('div.context-attribute-values .delete').click(function(){
            return confirm('Are you sure?');
            });
            });
            ";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "ConfirmDelete", script, true );
        }
예제 #4
0
        private void BindFilter()
        {
            ddlCategoryFilter.Items.Clear();
            ddlCategoryFilter.Items.Add( "[All]" );

            AttributeService attributeService = new AttributeService();
            var items = attributeService.Queryable().
                Where( a => a.Entity == entity &&
                    ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn &&
                    ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue &&
                    a.Category != "" && a.Category != null ).
                OrderBy( a => a.Category ).
                Select( a => a.Category ).
                Distinct().ToList();

            foreach ( var item in items )
                ddlCategoryFilter.Items.Add( item );
        }
예제 #5
0
        private void BindGrid()
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                AttributeService attributeService = new AttributeService();

                var queryable = attributeService.
                    Queryable().
                    Where( a => a.Entity == entity &&
                        ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn &&
                        ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue );

                if ( ddlCategoryFilter.SelectedValue != "[All]" )
                    queryable = queryable.
                        Where( a => a.Category == ddlCategoryFilter.SelectedValue );

                rGrid.DataSource = queryable.
                    OrderBy( a => a.Category ).
                    ThenBy( a => a.Name ).
                    Select( a => new
                    {
                        a.Id,
                        a.Category,
                        a.Name,
                        a.Description,
                        a.DefaultValue
                    } ).
                    ToList();

                rGrid.DataBind();
            }
        }