Example #1
0
        public async Task <IEnumerable <AADIdentity> > GetChannels(string groupId, HttpClient graphHttpClient)
        {
            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentException(nameof(groupId));
            }

            if (graphHttpClient == null)
            {
                throw new ArgumentException(nameof(graphHttpClient));
            }

            HttpResponseMessage response = await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/teams/{groupId}/channels");

            string responseMsg = await response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new AutoTeamsStructureException($"Get teams channel failed for {groupId}: {responseMsg}");
            }

            GraphDataSet <AADIdentity> dataSet = JsonConvert.DeserializeObject <GraphDataSet <AADIdentity> >(responseMsg);

            return(dataSet.Value);
        }
        private async Task <string> GetListId(HttpClient graphHttpClient, string groupId, string name)
        {
            HttpResponseMessage response =
                await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/groups/{groupId}/sites/root/lists");

            string responseMsg = await response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new AutoTeamsStructureException($"Get list in group failed for {groupId}: {response.StatusCode}-{responseMsg}");
            }

            GraphDataSet <JObject> dataSet = JsonConvert.DeserializeObject <GraphDataSet <JObject> >(responseMsg);
            JObject matchedObject          = dataSet.Value.FirstOrDefault(x =>
                                                                          x["name"].ToString().Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (matchedObject != null)
            {
                return(matchedObject["id"].ToString());
            }
            else
            {
                return(null);
            }
        }
        private async Task <List <JObject> > GetListItemsById(HttpClient graphHttpClient, string groupId,
                                                              string listId)
        {
            HttpResponseMessage response =
                await graphHttpClient.GetAsync(
                    $"{Settings.GraphBaseUri}/groups/{groupId}/sites/root/lists/{listId}/items?expand=fields");

            string responseMsg = await response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new AutoTeamsStructureException($"Get list items by id failed for {groupId}->{listId}: {response.StatusCode}-{responseMsg}");
            }

            GraphDataSet <JObject> dataSet = JsonConvert.DeserializeObject <GraphDataSet <JObject> >(responseMsg);

            return(dataSet.Value);
        }
Example #4
0
        public async Task <IEnumerable <AADIdentity> > GetGroups(HttpClient graphHttpClient)
        {
            if (graphHttpClient == null)
            {
                throw new ArgumentException(nameof(graphHttpClient));
            }

            HttpResponseMessage response = await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/groups");

            string responseMsg = await response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new AutoTeamsStructureException($"List groups graph call failed: {response.StatusCode}-{responseMsg}");
            }

            GraphDataSet <AADIdentity> dataSet = JsonConvert.DeserializeObject <GraphDataSet <AADIdentity> >(responseMsg);

            return(dataSet.Value);
        }