public IEnumerable <UserSearchModel> Resolve(MicrosoftGraphUserListResponse source, UserSearchResponseModel destination, List <MicrosoftGraphUserModel> sourceMember, IEnumerable <UserSearchModel> destMember, ResolutionContext context) { var results = context.Mapper.Map <List <UserSearchModel> >(sourceMember); var duplicates = from r in results where !string.IsNullOrWhiteSpace(r.Email) group r by new { r.DisplayName } into dupes where dupes.Count() > 1 select dupes; foreach (var duplicate in duplicates) { foreach (var d in duplicate) { d.DisplayName = $"{d.DisplayName} - {d.Email}"; } } var key = nameof(ActiveDirectoryUserSelectModel.NoneOption); if (context.Items.ContainsKey(key) && (bool)context.Items[key]) { results.Insert(0, new UserSearchModel() { DisplayName = "None" }); } return(results); }
public async Task <MicrosoftGraphUserListResponse> GetUsersAsync(string term, int count = 10) { var auth = await AuthenticateAsync(); var filter = $"$filter=startswith(displayName,'{term}') or startswith(givenName,'{term}') or startswith(surname,'{term}') or startswith(mail,'{term}') or startswith(userPrincipalName,'{term}')"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, $"https://graph.microsoft.com/v1.0/users?{filter}&{userSelect}&$top={count}"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", auth.AccessToken); HttpResponseMessage response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { throw new HttpResponseException(response.StatusCode); } string json = await response.Content.ReadAsStringAsync(); MicrosoftGraphUserListResponse users = JsonConvert.DeserializeObject <MicrosoftGraphUserListResponse>(json); return(users); }