/// <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); } }
/// <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); }
/// <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); } }
/// <summary> /// Gets the 'Security Role' Group Type. /// </summary> /// <returns></returns> public static GroupTypeCache GetSecurityRoleGroupType() { return(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid())); }
/// <summary> /// Gets the 'Family' Group Type. /// </summary> /// <returns></returns> public static GroupTypeCache GetFamilyGroupType() { return(GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid())); }
/// <summary> /// Removes groupType from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { FlushCache(GroupTypeCache.CacheKey(id)); }
/// <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))); }
/// <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))); }
/// <summary> /// Removes groupType from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { FlushCache(GroupTypeCache.CacheKey(id)); FlushCache("Rock:GroupType:All"); }
/// <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)); }