Esempio n. 1
0
        private static void UpdateGroupMemberShip(GraphClient graphClient, User user, List <Group> userGroups)
        {
            var groups = graphClient.GetAllGroups("");

            foreach (var group in groups.Values)
            {
                var groupMembers = graphClient.GetGroupMembers(group.ObjectId);
                if (groupMembers.Values.Any(u => u.ObjectId == user.ObjectId) &&
                    !userGroups.Any(x => x.ObjectId == group.ObjectId))
                {
                    graphClient.RemoveGroupMember(group.ObjectId, user.ObjectId);
                }
                if (!groupMembers.Values.Any(u => u.ObjectId == user.ObjectId) &&
                    userGroups.Any(x => x.ObjectId == group.ObjectId))
                {
                    graphClient.AddGroupMember(group.ObjectId, user.ObjectId);
                }
            }
        }