Exemple #1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="category">The category.</param>
        public void SetValue(Rock.Model.Category category)
        {
            if (category != null)
            {
                ItemId = category.Id.ToString();

                var parentCategoryIds = new List <string>();
                var parentCategory    = category.ParentCategory;
                while (parentCategory != null)
                {
                    if (!parentCategoryIds.Contains(parentCategory.Id.ToString()))
                    {
                        parentCategoryIds.Insert(0, parentCategory.Id.ToString());
                    }
                    else
                    {
                        // infinite recursion
                        break;
                    }
                    parentCategory = parentCategory.ParentCategory;
                }

                InitialItemParentIds = parentCategoryIds.AsDelimited(",");
                ItemName             = category.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Exemple #2
0
 private static CategoryCache LoadByModel(Rock.Model.Category categoryModel)
 {
     if (categoryModel != null)
     {
         return(new CategoryCache(categoryModel));
     }
     return(null);
 }
Exemple #3
0
        /// <summary>
        /// Adds Category model to cache, and returns cached object
        /// </summary>
        /// <param name="categoryModel">The categoryModel to cache</param>
        /// <returns></returns>
        public static CategoryCache Read(Rock.Model.Category categoryModel)
        {
            string cacheKey = CategoryCache.CacheKey(categoryModel.Id);

            ObjectCache   cache    = MemoryCache.Default;
            CategoryCache category = cache[cacheKey] as CategoryCache;

            if (category != null)
            {
                return(category);
            }
            else
            {
                category = new CategoryCache(categoryModel);

                var cachePolicy = new CacheItemPolicy();
                cache.Set(cacheKey, category, cachePolicy);
                cache.Set(category.Guid.ToString(), category.Id, cachePolicy);

                return(category);
            }
        }
Exemple #4
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="category">The category.</param>
        public void SetValue(Rock.Model.Category category)
        {
            if (category != null)
            {
                ItemId = category.Id.ToString();

                string parentCategoryIds = string.Empty;
                var    parentCategory    = category.ParentCategory;
                while (parentCategory != null)
                {
                    parentCategoryIds = parentCategory.Id + "," + parentCategoryIds;
                    parentCategory    = parentCategory.ParentCategory;
                }

                InitialItemParentIds = parentCategoryIds.TrimEnd(new char[] { ',' });
                ItemName             = category.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Exemple #5
0
 /// <summary>
 /// Adds Category model to cache, and returns cached object
 /// </summary>
 /// <param name="categoryModel">The categoryModel to cache</param>
 /// <returns></returns>
 public static CategoryCache Read(Rock.Model.Category categoryModel)
 {
     return(GetOrAddExisting(CategoryCache.CacheKey(categoryModel.Id),
                             () => LoadByModel(categoryModel)));
 }
Exemple #6
0
 private CategoryCache(Rock.Model.Category model)
 {
     CopyFromModel(model);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CategoryNavigationItem"/> class.
 /// </summary>
 /// <param name="category">The category.</param>
 public CategoryNavigationItem(Category category)
 {
     Category = category;
 }