private static async Task <bool> AddOwnerToGroup(UnifiedGroup group, User user, string accessToken) { string requestUrl = "https://graph.microsoft.com/v1.0/groups/" + group.id + "/owners/$ref"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var content = "{\"@odata.id\": \"https://graph.microsoft.com/v1.0/users/" + user.id + "\"}"; //JsonConvert.SerializeObject(user); request.Content = new StringContent(content, Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { HttpResponseMessage response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { //string responseString = await response.Content.ReadAsStringAsync(); return(true); } else { // Something went wrong... throw new Exception(await response.Content.ReadAsStringAsync()); } } }
private static async Task <UnifiedGroup> CreateGroup(string groupName, string desc, string nickname, string accessToken) { var newGroup = new NewGroup(); newGroup.Description = desc; newGroup.DisplayName = groupName; newGroup.GroupTypes = new List <string>(); newGroup.GroupTypes.Add("Unified"); newGroup.MailEnabled = true; newGroup.SecurityEnabled = false; newGroup.MailNickname = nickname; string requestUrl = "https://graph.microsoft.com/v1.0/groups"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); request.Content = new StringContent(JsonConvert.SerializeObject(newGroup), Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { HttpResponseMessage response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); UnifiedGroup group = JsonConvert.DeserializeObject <UnifiedGroup>(responseString); return(group); } else { // Something went wrong... throw new Exception(await response.Content.ReadAsStringAsync()); } } }
void LoadFromXml(EwsServiceXmlReader reader, String xmlElementName) { reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.UnifiedGroupsSet); do { reader.Read(); switch (reader.LocalName) { case XmlElementNames.FilterType: this.FilterType = (UnifiedGroupsFilterType)Enum.Parse(typeof(UnifiedGroupsFilterType), reader.ReadElementValue(), false); break; case XmlElementNames.TotalGroups: this.TotalGroups = reader.ReadElementValue <int>(); break; case XmlElementNames.GroupsTag: reader.Read(); while (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.UnifiedGroup)) { UnifiedGroup unifiedGroup = new UnifiedGroup(); unifiedGroup.LoadFromXml(reader, XmlElementNames.UnifiedGroup); this.unifiedGroups.Add(unifiedGroup); } // Skip end element. reader.EnsureCurrentNodeIsEndElement(XmlNamespace.NotSpecified, XmlElementNames.GroupsTag); reader.Read(); break; default: break; } }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.UnifiedGroupsSet)); // Skip end element reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.UnifiedGroupsSet); reader.Read(); }