public void SaveAttributeValues(int? personId) { Rock.Services.Cms.SiteService siteService = new Services.Cms.SiteService(); Rock.Models.Cms.Site siteModel = siteService.GetSite( this.Id ); if ( siteModel != null ) { siteService.LoadAttributes( siteModel ); if ( siteModel.Attributes != null ) foreach ( Rock.Models.Core.Attribute attribute in siteModel.Attributes ) siteService.SaveAttributeValue( 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="guid"></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.Services.Cms.SiteService siteService = new Services.Cms.SiteService(); Rock.Models.Cms.Site siteModel = siteService.GetSite( 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; siteService.LoadAttributes( siteModel ); foreach ( Rock.Models.Core.Attribute attribute in siteModel.Attributes ) { site.AttributeIds.Add( attribute.Id ); Attribute.Read( attribute ); } site.AttributeValues = siteModel.AttributeValues; cache.Set( cacheKey, site, new CacheItemPolicy() ); return site; } else return null; } }