Exemple #1
0
        public async Task <string> CreateGroupAsyn(NewTeamDetails newTeamDetails)
        {
            string endpoint = ApplicationSettings.GraphApiEndpoint + "groups/";

            GroupInfo groupInfo = new GroupInfo()
            {
                description     = "Team for " + newTeamDetails.TeamName,
                displayName     = newTeamDetails.TeamName,
                groupTypes      = new string[] { "Unified" },
                mailEnabled     = true,
                mailNickname    = newTeamDetails.TeamName.Replace(" ", "").Replace("-", "") + DateTime.Now.Second,
                securityEnabled = true,
                ownersodatabind = newTeamDetails.OwnerADIds.Select(userId => "https://graph.microsoft.com/v1.0/users/" + userId).ToArray()
            };

            return(await PostRequest(endpoint, JsonConvert.SerializeObject(groupInfo)));
        }
Exemple #2
0
        public async Task <string> CreateNewTeam(NewTeamDetails teamDetails)
        {
            var groupId = await CreateGroupAsyn(teamDetails);

            if (IsValidGuid(groupId))
            {
                await Common.ForEachAsync(teamDetails.UserADIds, 10,
                                          async userid =>
                {
                    var result = await AddTeamMemberAsync(groupId, userid);
                    if (!result)
                    {
                        Console.WriteLine($"Failed to add {userid} to {teamDetails.TeamName}. Check if user is already part of this team.");
                    }
                }
                                          );

                Console.WriteLine($"O365 Group is created for {teamDetails.TeamName}.");
                // Sometimes Team creation fails due to internal error. Added rety mechanism.
                var    retryCount = 4;
                string teamId     = null;
                do
                {
                    teamId = await CreateTeamAsyn(groupId); // getting response as 403: forbidden

                    if (IsValidGuid(teamId))
                    {
                        return(teamId);
                    }
                    else
                    {
                        teamId = null;
                    }
                    retryCount--;
                    await Task.Delay(5000);
                } while (retryCount > 0);
            }
            return(null);
        }