Created
March 9, 2018 04:47
-
-
Save Sam7/ee57bce4435b2839191d498b684dc07a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void RemoveGroups(BackOfficeIdentityUser autoLinkUser, IReadOnlyUserGroup[] groupsToRemove) | |
{ | |
// remove old groups | |
// for some reason it only works if we adjust the groups first and then the roles. | |
// only works when both are changed and only in that order :S | |
var groups = autoLinkUser.Groups.ToList(); | |
foreach (var adGroup in groupsToRemove) groups.RemoveAll(x => x.Alias.Equals(adGroup.Alias)); | |
autoLinkUser.Groups = groups.ToArray(); | |
// the same for roles | |
foreach (var adGroup in groupsToRemove) | |
{ | |
var userRole = autoLinkUser.Roles.FirstOrDefault(x => x.RoleId.Equals(adGroup.Alias)); | |
if (userRole == null) continue; | |
autoLinkUser.Roles.Remove(userRole); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment