Rock.Model.CategoryService.Get C# (CSharp) Method

Get() public method

Returns a queryable collection of Rock.Model.Category">Categories by parent Rock.Model.EntityType.
public Get ( int ParentId, int entityTypeId ) : IQueryable
ParentId int A representing the CategoryID of the parent to search by. To find Categories /// that do not inherit from a parent category, this value will be null.
entityTypeId int A representing the EntityTypeId of the to search by.
return IQueryable
        public IQueryable<Category> Get( int? ParentId, int? entityTypeId )
        {
            var query = Queryable()
                .Where( c => ( c.ParentCategoryId ?? 0 ) == ( ParentId ?? 0 ) );

            if ( entityTypeId.HasValue )
            {
                query = query.Where( c => c.EntityTypeId == entityTypeId.Value );
            }

            return query
                .OrderBy( t => t.Order )
                .ThenBy( t => t.Name );
        }

Same methods

CategoryService::Get ( string name, int entityTypeId, string entityTypeQualifierColumn, string entityTypeQualifierValue ) : IQueryable

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Returns Category object from cache.  If category does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Category to read</param>
        /// <returns></returns>
        public static CategoryCache Read(int id)
        {
            string cacheKey = CategoryCache.CacheKey(id);

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

            if (category != null)
            {
                return(category);
            }
            else
            {
                var categoryService = new Rock.Model.CategoryService();
                var categoryModel   = categoryService.Get(id);
                if (categoryModel != null)
                {
                    category = new CategoryCache(categoryModel);

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

                    return(category);
                }
                else
                {
                    return(null);
                }
            }
        }
All Usage Examples Of Rock.Model.CategoryService::Get