示例#1
0
        /// <summary>
        /// Loads the by identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public static RoleCache LoadById(int id)
        {
            using (var rockContext = new RockContext())
            {
                var securityGroupType   = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid(), rockContext);
                var securityGroupTypeId = securityGroupType?.Id ?? 0;

                var groupService       = new Model.GroupService(rockContext);
                var groupMemberService = new Model.GroupMemberService(rockContext);
                var groupModel         = groupService.Get(id);

                if (groupModel == null || !groupModel.IsActive ||
                    (!groupModel.IsSecurityRole && groupModel.GroupTypeId != securityGroupTypeId))
                {
                    return(null);
                }

                var role = new RoleCache
                {
                    Id     = groupModel.Id,
                    Guid   = groupModel.Guid,
                    Name   = groupModel.Name,
                    People = new ConcurrentDictionary <Guid, bool>()
                };

                var groupMembersQry = groupMemberService.Queryable().Where(a => a.GroupId == groupModel.Id);

                // Add the members
                foreach (var personGuid in groupMembersQry
                         .Where(m => m.GroupMemberStatus == Model.GroupMemberStatus.Active)
                         .Select(m => m.Person.Guid)
                         .ToList()
                         .Distinct())
                {
                    role.People.TryAdd(personGuid, true);
                }

                role.IsSecurityTypeGroup = groupModel.GroupTypeId == securityGroupTypeId;

                return(role);
            }
        }
示例#2
0
        /// <summary>
        /// Returns a list of all the possible Roles
        /// </summary>
        /// <returns></returns>
        public static List <RoleCache> AllRoles()
        {
            var roles = new List <RoleCache>();

            var securityGroupType   = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid());
            var securityGroupTypeId = securityGroupType?.Id ?? 0;

            var groupService = new Model.GroupService(new RockContext());

            foreach (var id in groupService.Queryable()
                     .Where(g =>
                            g.IsActive &&
                            (g.GroupTypeId == securityGroupTypeId || g.IsSecurityRole))
                     .OrderBy(g => g.Name)
                     .Select(g => g.Id)
                     .ToList())
            {
                roles.Add(Get(id));
            }

            return(roles);
        }
示例#3
0
        /// <summary>
        /// Reads the specified field type model.
        /// </summary>
        /// <param name="groupTypeModel">The field type model.</param>
        /// <returns></returns>
        public static GroupTypeCache Read(GroupType groupTypeModel)
        {
            string cacheKey = GroupTypeCache.CacheKey(groupTypeModel.Id);

            ObjectCache    cache     = MemoryCache.Default;
            GroupTypeCache groupType = cache[cacheKey] as GroupTypeCache;

            if (groupType != null)
            {
                return(groupType);
            }
            else
            {
                groupType = new GroupTypeCache(groupTypeModel);

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

                return(groupType);
            }
        }
示例#4
0
 /// <summary>
 /// Gets the 'Security Role' Group Type.
 /// </summary>
 /// <returns></returns>
 public static GroupTypeCache GetSecurityRoleGroupType()
 {
     return(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid()));
 }
示例#5
0
 /// <summary>
 /// Gets the 'Family' Group Type.
 /// </summary>
 /// <returns></returns>
 public static GroupTypeCache GetFamilyGroupType()
 {
     return(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()));
 }
示例#6
0
 /// <summary>
 /// Removes groupType from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(GroupTypeCache.CacheKey(id));
 }
示例#7
0
 /// <summary>
 /// Reads the specified field type model.
 /// </summary>
 /// <param name="groupTypeModel">The field type model.</param>
 /// <returns></returns>
 public static GroupTypeCache Read(GroupType groupTypeModel)
 {
     return(GetOrAddExisting(GroupTypeCache.CacheKey(groupTypeModel.Id),
                             () => LoadByModel(groupTypeModel)));
 }
示例#8
0
 /// <summary>
 /// Returns GroupType object from cache.  If groupType does not already exist in cache, it
 /// will be read and added to cache
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="rockContext">The rock context.</param>
 /// <returns></returns>
 public static GroupTypeCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(GroupTypeCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }
示例#9
0
        /// <summary>
        /// Removes groupType from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            FlushCache(GroupTypeCache.CacheKey(id));

            FlushCache("Rock:GroupType:All");
        }
示例#10
0
        /// <summary>
        /// Removes groupType from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(GroupTypeCache.CacheKey(id));
        }