/// <summary> /// Returns Block object from cache. If block does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static BlockCache Read(int id) { string cacheKey = BlockCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; BlockCache block = cache[cacheKey] as BlockCache; if (block != null) { return(block); } else { var blockService = new Model.BlockService(); var blockModel = blockService.Get(id); if (blockModel != null) { blockModel.LoadAttributes(); block = BlockCache.CopyModel(blockModel); cache.Set(cacheKey, block, new CacheItemPolicy()); return(block); } else { return(null); } } }
/// <summary> /// Saves the attribute values. /// </summary> /// <param name="personId">The person id.</param> public void SaveAttributeValues(int?personId) { var blockService = new Model.BlockService(); var blockModel = blockService.Get(this.Id); if (blockModel != null) { blockModel.LoadAttributes(); foreach (var attribute in blockModel.Attributes) { Rock.Attribute.Helper.SaveAttributeValues(blockModel, attribute.Value, this.AttributeValues[attribute.Key], personId); } } }
/// <summary> /// Reloads the attribute values. /// </summary> public void ReloadAttributeValues() { var blockService = new Model.BlockService(); var blockModel = blockService.Get(this.Id); if (blockModel != null) { blockModel.LoadAttributes(); this.AttributeValues = blockModel.AttributeValues; this.AttributeIds = new List <int>(); if (blockModel.Attributes != null) { foreach (var attribute in blockModel.Attributes) { this.AttributeIds.Add(attribute.Value.Id); } } } }