private void listUserTabUserGroups_SelectedIndexChanged(object sender, EventArgs e) { if (_isFillingList || SelectedUser == null) { return; } if (listUserTabUserGroups.SelectedItems.OfType <ODBoxItem <UserGroup> >().Select(x => x.Tag.UserGroupNum).Count() == 0) { MsgBox.Show(this, "A user must have at least one User Group attached."); RefreshUserTabGroups(); //set the groups back to what they were before. return; } List <long> listSelectedUserUserGroupsOld = SelectedUser.GetGroups(IsForCEMT).Select(x => x.UserGroupNum).ToList(); List <long> listSelectedUserUserGroups = listUserTabUserGroups.SelectedTags <UserGroup>().Select(x => x.UserGroupNum).ToList(); if ( //Current selected groups do not contain SecurityAdmin permission GroupPermissions.GetForUserGroups(listSelectedUserUserGroups, Permissions.SecurityAdmin).Count == 0 //Selected user had SecurityAdmin permission before new selections && GroupPermissions.GetForUserGroups(listSelectedUserUserGroupsOld, Permissions.SecurityAdmin).Count > 0) { //The SelectedUser is no longer part of SecurityAdmin group. Check that at least one other user is part of a SecurityAdmin Group. if (!Userods.IsSomeoneElseSecurityAdmin(SelectedUser)) { MsgBox.Show(this, Lan.g(this, "At least one user must have Security Admin permission.")); RefreshUserTabGroups(); //set the groups back to what they were before. return; } } if (UserGroupAttaches.SyncForUser(SelectedUser, listSelectedUserUserGroups) != 0) { UserGroupAttaches.RefreshCache(); //only refreshes local cache. } RefreshUserTree(); }