public async Task AddGroupsAndUsersAsync(GraphService graphService)
        {
            List <string> newUsers = new List <string>();

            #region Create AD Group
            var groupsDict = new Dictionary <string, Graph.Group>();

            XmlNode groupItems = sampleData.SelectSingleNode("//List[@name='AD Groups']");

            foreach (XmlNode item in groupItems.ChildNodes)
            {
                string displayName  = item.Attributes["DisplayName"].Value;
                string description  = item.Attributes["Description"].Value;
                string mailNickname = item.Attributes["MailNickname"].Value;

                var group = await GraphServiceExtension.GetGroupByDisplayNameAsync(graphService, displayName);

                if (group == null)
                {
                    group = await GraphServiceExtension.AddGroupAsync(graphService, mailNickname, displayName, description);
                }
                groupsDict.Add(displayName, group as Graph.Group);
            }
            #endregion

            #region Create AD Users
            XmlNode userItems = sampleData.SelectSingleNode("//List[@name='AD Users']");
            foreach (XmlNode item in userItems)
            {
                string displayName         = item.Attributes["DisplayName"].Value;
                string userPrincipalName   = item.Attributes["PrincipalName"].Value;
                string password            = item.Attributes["Password"].Value;
                string ownGroupDisplayName = item.Attributes["GroupsDisplayName"].Value;

                Graph.IUser user = await GraphServiceExtension.GetFirstUserAsync(graphService, i => i.displayName == displayName);

                if (user == null)
                {
                    user = await GraphServiceExtension.AddUserAsync(graphService, userPrincipalName, displayName, password);

                    await GraphServiceExtension.AssignLicenseAsyncViaHttpClientAsync(graphService, user as Graph.User);
                }

                if (groupsDict.ContainsKey(ownGroupDisplayName) &&
                    (await GraphServiceExtension.GetGroupMembersAsync(graphService, ownGroupDisplayName))
                    .Where(i => i.userPrincipalName == user.userPrincipalName).Count() == 0)
                {
                    groupsDict[ownGroupDisplayName].members.Add(user as Graph.User);
                    await groupsDict[ownGroupDisplayName].SaveChangesAsync();
                }

                newUsers.Add(user.userPrincipalName);
            }
            #endregion

            AddUsersToSPGroup(newUsers);
        }
        private async Task <RepairPeople> GetRepairPeopleByEmailAddressAsync(string userPrincipalName)
        {
            Graph.GraphService graphService = await AuthenticationHelper.GetGraphServiceAsync();

            Microsoft.Graph.IUser repairPeople = await GraphServiceExtension.GetFirstUserAsync(graphService, i => i.mail == userPrincipalName);

            if (repairPeople == null)
            {
                return(null);
            }

            return(new RepairPeople()
            {
                Title = repairPeople.displayName,
                sl_emailaddress = repairPeople.userPrincipalName
            });
        }