public async Task <IActionResult> List()
        {
            var model = new TeamsListDisplayModel();

            await EnsureScopes(_teamsScopes);

            try
            {
                // Get all groups
                // Graph v1 doesn't support filtering on resourceProvisioningOptions,
                // which is the property that tells us if the group has a team or not
                // So we'll get all unified groups, then sort them into their respective
                // lists in the display model

                IList <Group> allGroups;

                // GET /groups
                var groupsPage = await _graphClient.Groups
                                 .Request()
                                 // Only get unified groups (Teams groups must be unified)
                                 .Filter("groupTypes/any(a:a%20eq%20'unified')")
                                 // Only get the fields used by the view
                                 .Select("displayName,id,resourceProvisioningOptions")
                                 // Limit results to the default page size
                                 .Top(GraphConstants.PageSize)
                                 .GetAsync();

                // If there are more results available, use a
                // page iterator to get all results
                if (groupsPage.NextPageRequest == null)
                {
                    allGroups = groupsPage.CurrentPage;
                }
                else
                {
                    allGroups = await GetAllPages <Group>(
                        _graphClient, groupsPage);
                }

                // Add each group to the appropriate list
                foreach (var group in allGroups)
                {
                    // Groups with Teams will have "Team" in their resourceProvisioningOptions
                    if (group.AdditionalData["resourceProvisioningOptions"] is JsonElement rpOptions &&
                        rpOptions.ValueKind == JsonValueKind.Array &&
                        rpOptions.EnumerateArray().Any(e => e.GetString().Equals("team", StringComparison.InvariantCultureIgnoreCase)))
                    //if (rpOptions != null && rpOptions.Contains("team", StringComparer.InvariantCultureIgnoreCase))
                    //if (optionsArray.Contains("team", StringComparer.InvariantCultureIgnoreCase))
                    {
                        model.AllTeams.Add(group);
                    }
                    else
                    {
                        model.AllNonTeamGroups.Add(group);
                    }
                }
        // GET /Teams/List
        // Get the list of teams, groups that teams can be added to,
        // and teams the user is a member of
        public async Task <IActionResult> List()
        {
            var model = new TeamsListDisplayModel();

            try
            {
                var graphClient = GetGraphClientForScopes(teamScopes);

                // Get all groups
                // Graph v1 doesn't support filtering on resourceProvisioningOptions,
                // which is the property that tells us if the group has a team or not
                // So we'll get all unified groups, then sort them into their respective
                // lists in the display model

                IList <Group> allGroups;

                // GET /groups
                var groupsPage = await graphClient.Groups
                                 .Request()
                                 // Only get unified groups (Teams groups must be unified)
                                 .Filter("groupTypes/any(a:a%20eq%20'unified')")
                                 // Only get the fields used by the view
                                 .Select("displayName,id,resourceProvisioningOptions")
                                 // Limit results to the default page size
                                 .Top(GraphConstants.PageSize)
                                 .GetAsync();

                // If there are more results available, use a
                // page iterator to get all results
                if (groupsPage.NextPageRequest == null)
                {
                    allGroups = groupsPage.CurrentPage;
                }
                else
                {
                    allGroups = await GetAllPages <Group>(
                        graphClient, groupsPage);
                }

                // Add each group to the appropriate list
                foreach (var group in allGroups)
                {
                    // Groups with Teams will have "Team" in their resourceProvisioningOptions
                    var rpOptions = group.AdditionalData["resourceProvisioningOptions"]
                                    as Newtonsoft.Json.Linq.JArray;

                    var optionsArray = rpOptions.ToObject <string[]>();

                    if (optionsArray.Contains("team", StringComparer.InvariantCultureIgnoreCase))
                    {
                        model.AllTeams.Add(group);
                    }
                    else
                    {
                        model.AllNonTeamGroups.Add(group);
                    }
                }

                // GET /me/joinedTeams
                var joinedTeamsPage = await graphClient.Me
                                      .JoinedTeams
                                      .Request()
                                      .GetAsync();

                if (joinedTeamsPage.NextPageRequest == null)
                {
                    model.JoinedTeams = joinedTeamsPage.CurrentPage;
                }
                else
                {
                    model.JoinedTeams = await GetAllPages <Team>(
                        graphClient, joinedTeamsPage);
                }

                return(View(model));
            }
            catch (ServiceException ex)
            {
                InvokeAuthIfNeeded(ex);

                return(RedirectToAction("Error", "Home")
                       .WithError($"Error getting teams",
                                  ex.Error.Message));
            }
        }