private static async Task <bool> RemoveGroupOwner(string grpName, string userName) { try { // get object id for userPrincipalName var userObjectId = GetUserObjectId(userName).GetAwaiter().GetResult(); // get object id fro group name var groupObjectId = GetGroupObjectId(grpName).GetAwaiter().GetResult(); AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json"); // call MS Graph Api function that attaches a member to the group var httpClient = new HttpClient(); var apiCaller = new ProtectedApiCallHelper(httpClient); await apiCaller.DeleteWebApiAndProcessResultASync($"{config.ApiUrl}v1.0/groups/{groupObjectId}/owners/{userObjectId}/$ref", Program.AuthenticationResult.AccessToken); return(true); } catch (Exception ex) { return(false); } }
private static async Task DeleteGroup(string groupName) { AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json"); try { var groupId = MsGraphFacade.GetGroupObjectId(groupName).GetAwaiter().GetResult(); var httpClient = new HttpClient(); var apiCaller = new ProtectedApiCallHelper(httpClient); await apiCaller.DeleteWebApiAndProcessResultASync($"{config.ApiUrl}v1.0/groups/{groupId}", Program.AuthenticationResult.AccessToken); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }