public async Task <PersonGroupResult> CreatePersonGroupIfNotExistsAsync(string personGroupName) { PersonGroupResult personGroupResult = (await this.GetPersonGroupsAsync())?.Where(i => i.Name == personGroupName).FirstOrDefault(); if (personGroupResult == null) { personGroupResult = await this.CreatePersonGroup(new PersonGroup { Name = personGroupName }); } return(personGroupResult); }
public async Task <PersonGroupResult> CreatePersonGroup(PersonGroup personGroup) { PersonGroupResult personGroupResult = null; try { personGroupResult = await PostAsync <PersonGroupResult, PersonGroup>(PersonGroupsEndpoint, personGroup, (request) => this.ConfigureRequestWithSubscriptionHeader(request)); } catch { // TODO: Log exception here } return(personGroupResult); }
public async static Task <PersonGroupResult> CreatePersonGroupAsync(string displayName) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Common.CoreConstants.FaceApiSubscriptionKey); string groupId = displayName.Replace(" ", "").ToLower(); PersonGroupInfo groupInfo = new PersonGroupInfo() { name = displayName, userData = "", }; var payload = new HttpStringContent(JsonConvert.SerializeObject(groupInfo)); payload.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json"); var response = await client.PutAsync(new Uri($"{CogsExplorer.Common.CoreConstants.CognitiveServicesBaseUrl}/face/v1.0/persongroups/{groupId}"), payload); PersonGroupResult personGroupResult = null; try { var results = await response.Content.ReadAsStringAsync(); personGroupResult = new PersonGroupResult() { personGroupId = groupId, name = displayName, userData = "", }; } catch (Exception ex) { } return(personGroupResult); }