/// <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); } } }
/// <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); } } } } } }
/// <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); } } } }
/// <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 ); } }
/// <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 ); } } }
/// <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; } }