/// <summary> /// Returns Site object from cache. If site does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static Site Read(int id) { string cacheKey = Site.CacheKey(id); ObjectCache cache = MemoryCache.Default; Site site = cache[cacheKey] as Site; if (site != null) { return(site); } else { Rock.CMS.SiteService siteService = new CMS.SiteService(); Rock.CMS.Site siteModel = siteService.Get(id); if (siteModel != null) { site = new Site(); site.Id = siteModel.Id; site.Name = siteModel.Name; site.Description = siteModel.Description; site.Theme = siteModel.Theme; site.DefaultPageId = siteModel.DefaultPageId; site.AppleTouchUrl = siteModel.AppleTouchIconUrl; site.FaviconUrl = siteModel.FaviconUrl; site.FacebookAppId = siteModel.FacebookAppId; site.FacebookAppSecret = siteModel.FacebookAppSecret; Rock.Attribute.Helper.LoadAttributes(siteModel); foreach (var category in siteModel.Attributes) { foreach (var attribute in category.Value) { site.AttributeIds.Add(attribute.Id); } } site.AttributeValues = siteModel.AttributeValues; site.AuthEntity = siteModel.AuthEntity; site.SupportedActions = siteModel.SupportedActions; cache.Set(cacheKey, site, new CacheItemPolicy()); return(site); } else { return(null); } } }
/// <summary> /// Saves the attribute values. /// </summary> /// <param name="personId">The person id.</param> public void SaveAttributeValues(int?personId) { Rock.CMS.SiteService siteService = new CMS.SiteService(); Rock.CMS.Site siteModel = siteService.Get(this.Id); if (siteModel != null) { Rock.Attribute.Helper.LoadAttributes(siteModel); if (siteModel.Attributes != null) { foreach (var category in siteModel.Attributes) { foreach (var attribute in category.Value) { Rock.Attribute.Helper.SaveAttributeValues(siteModel, 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.SiteService siteService = new CMS.SiteService(); Rock.CMS.Site siteModel = siteService.Get( this.Id ); if ( siteModel != null ) { Rock.Attribute.Helper.LoadAttributes( siteModel ); if ( siteModel.Attributes != null ) foreach ( var category in siteModel.Attributes ) foreach ( var attribute in category.Value ) Rock.Attribute.Helper.SaveAttributeValues( siteModel, attribute, this.AttributeValues[attribute.Key].Value, personId ); } }
/// <summary> /// Returns Site object from cache. If site does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static Site Read( int id ) { string cacheKey = Site.CacheKey( id ); ObjectCache cache = MemoryCache.Default; Site site = cache[cacheKey] as Site; if ( site != null ) return site; else { Rock.CMS.SiteService siteService = new CMS.SiteService(); Rock.CMS.Site siteModel = siteService.Get( id ); if ( siteModel != null ) { site = new Site(); site.Id = siteModel.Id; site.Name = siteModel.Name; site.Description = siteModel.Description; site.Theme = siteModel.Theme; site.DefaultPageId = siteModel.DefaultPageId; site.AppleTouchUrl = siteModel.AppleTouchIconUrl; site.FaviconUrl = siteModel.FaviconUrl; site.FacebookAppId = siteModel.FacebookAppId; site.FacebookAppSecret = siteModel.FacebookAppSecret; Rock.Attribute.Helper.LoadAttributes( siteModel ); foreach ( var category in siteModel.Attributes ) foreach ( var attribute in category.Value ) site.AttributeIds.Add( attribute.Id ); site.AttributeValues = siteModel.AttributeValues; site.AuthEntity = siteModel.AuthEntity; site.SupportedActions = siteModel.SupportedActions; cache.Set( cacheKey, site, new CacheItemPolicy() ); return site; } else return null; } }