private void CheckForAutoDemotion() { var autoLeaderOrgPromotionSetting = DbUtil.Db.Setting(AutoOrgLeaderPromotion); if (!autoLeaderOrgPromotionSetting) { return; } var autoPromoteCustom = GetAutoPromoteCustomSetting(); var isPromotingFromLeader = LeaderTypeIds.Contains(OrgMember.MemberTypeId.ToString()) && !LeaderTypeIds.Contains(MemberType.Value); var users = DbUtil.Db.Users.Where(us => us.PeopleId == PeopleId); if (!users.Any()) { return; } foreach (var user in users) { if (autoPromoteCustom != null && user.Roles.Contains(autoPromoteCustom.NewRole)) { if (user.Roles.Count() == 3 && user.InRole(OrgLeadersOnlyRole) && user.InRole(AccessRole) && user.InRole(autoPromoteCustom.NewRole) && !DbUtil.Db.OrganizationMembers.Any(x => x.MemberType.Id == (OrgMember.Organization.LeaderMemberTypeId > 0 ? OrgMember.Organization.LeaderMemberTypeId : DefaultLeaderMemberTypeId) && x.PeopleId == PeopleId && x.OrganizationId != Organization.OrganizationId)) { user.RemoveRoles(DbUtil.Db, autoPromoteCustom.NewRole); } } if (isPromotingFromLeader) { if (user.Roles.Count() == 2 && user.InRole(OrgLeadersOnlyRole) && user.InRole(AccessRole) && !DbUtil.Db.OrganizationMembers.Any( x => x.MemberType.Id == (OrgMember.Organization.LeaderMemberTypeId > 0 ? OrgMember.Organization.LeaderMemberTypeId : DefaultLeaderMemberTypeId) && x.PeopleId == PeopleId && x.OrganizationId != Organization.OrganizationId)) { // Resets their roles back to a "MyData" user user.SetRoles(DbUtil.Db, new string[] { }); } } } }
private void CheckForAutoPromotion() { var autoLeaderOrgPromotionSetting = DbUtil.Db.Setting(AutoOrgLeaderPromotion); if (!autoLeaderOrgPromotionSetting) { return; } var isPromotingToLeader = !LeaderTypeIds.Contains(OrgMember.MemberTypeId.ToString()) && LeaderTypeIds.Contains(MemberType.Value); var autoPromoteCustom = GetAutoPromoteCustomSetting(); if (autoPromoteCustom != null && autoPromoteCustom.NewMemberType != MemberType.ToString()) { autoPromoteCustom = null; } var users = DbUtil.Db.Users.Where(us => us.PeopleId == PeopleId); if (!users.Any()) { return; } foreach (var user in users) { if (!user.Roles.Any() && isPromotingToLeader) { user.AddRoles(DbUtil.Db, !user.InRole(AccessRole) ? new[] { AccessRole, OrgLeadersOnlyRole } : new[] { OrgLeadersOnlyRole }); } if (autoPromoteCustom != null) { user.AddRoles(DbUtil.Db, autoPromoteCustom.NewRole); } } }