Esempio n. 1
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public void SaveAttributeValues(int?personId)
        {
            Rock.Model.SiteService siteService = new Model.SiteService();
            Rock.Model.Site        siteModel   = siteService.Get(this.Id);
            if (siteModel != null)
            {
                siteModel.LoadAttributes();

                if (siteModel.Attributes != null)
                {
                    foreach (var attribute in siteModel.Attributes)
                    {
                        Rock.Attribute.Helper.SaveAttributeValues(siteModel, attribute.Value, this.AttributeValues[attribute.Key], personId);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <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 SiteCache Read(int id)
        {
            string cacheKey = SiteCache.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            SiteCache   site  = cache[cacheKey] as SiteCache;

            if (site != null)
            {
                return(site);
            }
            else
            {
                Rock.Model.SiteService siteService = new Model.SiteService();
                Rock.Model.Site        siteModel   = siteService.Get(id);
                if (siteModel != null)
                {
                    site = new SiteCache(siteModel);

                    siteModel.LoadAttributes();

                    foreach (var attribute in siteModel.Attributes)
                    {
                        site.AttributeIds.Add(attribute.Value.Id);
                    }

                    site.AttributeValues = siteModel.AttributeValues;

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

                    return(site);
                }
                else
                {
                    return(null);
                }
            }
        }