private static async Task ArchiveTeamAsync(string accessToken, ArchiveTeamRequest request) { // Initialize Graph client var graphClient = new GraphService(accessToken, logger); // Find groups with the specified SharePoint item ID var groupsToArchive = await graphClient.FindGroupsBySharePointItemIdAsync(request.SharePointItemId); foreach (var group in groupsToArchive.Value) { // Archive each matching team await graphClient.ArchiveTeamAsync(group.Id); } }
public static async Task ArchiveTeamAsync(FlightTeam team) { var crew = await graphClient.GetUserIds(team.Pilots, team.FlightAttendants); // Remove event from crew calendars await TeamProvisioning.RemoveFlightFromCalendars(crew, team.FlightNumber); // Archive team try { await graphClient.ArchiveTeamAsync(team.TeamId); } catch (ServiceException ex) { logger.LogInformation($"Attempt to archive team failed: {ex.Message}"); } }
public static async Task RemoveAllTeamsAsync(string accessToken) { // Initialize Graph client var graphClient = new GraphService(accessToken, logger); bool more = true; do { var groups = await graphClient.GetAllGroupsAsync("startswith(displayName, 'Flight')"); more = groups.Value.Count > 0; foreach (var group in groups.Value) { if (group.DisplayName != "Flight Admin") { logger.Info($"Deleting team {group.DisplayName}"); // Archive the team try { await graphClient.ArchiveTeamAsync(group.Id); } catch (Exception ex) { if (ex.Message.Contains("ItemNotFound")) { logger.Info("No team found"); } else { throw ex; } } // Delete the group await graphClient.DeleteGroupAsync(group.Id); } } }while (more); }