Ejemplo n.º 1
0
        /// <summary>
        /// Returns BlockInstance object from cache.  If blockInstance does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BlockInstance Read(int id)
        {
            string cacheKey = BlockInstance.CacheKey(id);

            ObjectCache   cache         = MemoryCache.Default;
            BlockInstance blockInstance = cache[cacheKey] as BlockInstance;

            if (blockInstance != null)
            {
                return(blockInstance);
            }
            else
            {
                Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
                Rock.CMS.BlockInstance        blockInstanceModel   = blockInstanceService.Get(id);
                if (blockInstanceModel != null)
                {
                    Rock.Attribute.Helper.LoadAttributes(blockInstanceModel);

                    blockInstance = BlockInstance.CopyModel(blockInstanceModel);

                    cache.Set(cacheKey, blockInstance, new CacheItemPolicy());

                    return(blockInstance);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reloads the attribute values.
        /// </summary>
        public void ReloadAttributeValues()
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
                Rock.CMS.BlockInstance        blockInstanceModel   = blockInstanceService.Get(this.Id);

                if (blockInstanceModel != null)
                {
                    Rock.Attribute.Helper.LoadAttributes(blockInstanceModel);

                    this.AttributeValues = blockInstanceModel.AttributeValues;

                    this.AttributeIds = new List <int>();
                    if (blockInstanceModel.Attributes != null)
                    {
                        foreach (var category in blockInstanceModel.Attributes)
                        {
                            foreach (var attribute in category.Value)
                            {
                                this.AttributeIds.Add(attribute.Id);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public void SaveAttributeValues(int?personId)
        {
            Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
            Rock.CMS.BlockInstance        blockInstanceModel   = blockInstanceService.Get(this.Id);

            if (blockInstanceModel != null)
            {
                Rock.Attribute.Helper.LoadAttributes(blockInstanceModel);
                foreach (var category in blockInstanceModel.Attributes)
                {
                    foreach (var attribute in category.Value)
                    {
                        Rock.Attribute.Helper.SaveAttributeValues(blockInstanceModel, attribute, this.AttributeValues[attribute.Key].Value, personId);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public void SaveAttributeValues(int? personId)
        {
            Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
            Rock.CMS.BlockInstance blockInstanceModel = blockInstanceService.Get( this.Id );

            if ( blockInstanceModel != null )
            {
                Rock.Attribute.Helper.LoadAttributes( blockInstanceModel );
                foreach ( var category in blockInstanceModel.Attributes )
                    foreach ( var attribute in category.Value )
                        Rock.Attribute.Helper.SaveAttributeValues( blockInstanceModel, attribute, this.AttributeValues[attribute.Key].Value, personId );
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reloads the attribute values.
        /// </summary>
        public void ReloadAttributeValues()
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
                Rock.CMS.BlockInstance blockInstanceModel = blockInstanceService.Get( this.Id );

                if ( blockInstanceModel != null )
                {
                    Rock.Attribute.Helper.LoadAttributes( blockInstanceModel );

                    this.AttributeValues = blockInstanceModel.AttributeValues;

                    this.AttributeIds = new List<int>();
                    if ( blockInstanceModel.Attributes != null )
                        foreach ( var category in blockInstanceModel.Attributes )
                            foreach ( var attribute in category.Value )
                                this.AttributeIds.Add( attribute.Id );
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns BlockInstance object from cache.  If blockInstance does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BlockInstance Read( int id )
        {
            string cacheKey = BlockInstance.CacheKey( id );

            ObjectCache cache = MemoryCache.Default;
            BlockInstance blockInstance = cache[cacheKey] as BlockInstance;

            if ( blockInstance != null )
                return blockInstance;
            else
            {
                Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
                Rock.CMS.BlockInstance blockInstanceModel = blockInstanceService.Get( id );
                if ( blockInstanceModel != null )
                {
                    Rock.Attribute.Helper.LoadAttributes( blockInstanceModel );

                    blockInstance = BlockInstance.CopyModel( blockInstanceModel );

                    cache.Set( cacheKey, blockInstance, new CacheItemPolicy() );

                    return blockInstance;
                }
                else
                    return null;
            }
        }