Esempio n. 1
0
        public async Task <SearchStudentsRS> SearchStudentsAsync(SearchStudentsRQ model)
        {
            if (model == null || model.PageSize <= 0)
            {
                throw new ArgumentException();
            }

            GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserReadBasicAll });
            var qry = graphClient.Users.Request();

            #region SetUserFilters
            var filters = new List <string>();

            if (!string.IsNullOrEmpty(model.FirstNameStartsWith))
            {
                filters.Add($"startswith(givenName,+'{model.FirstNameStartsWith}')");
            }

            if (!string.IsNullOrEmpty(model.LastNameStartsWith))
            {
                filters.Add($"startswith(surname,+'{model.LastNameStartsWith}')");
            }

            if (!string.IsNullOrEmpty(model.EmailStartsWith))
            {
                filters.Add($"startswith(mail,+'{model.EmailStartsWith}')");
            }

            if (filters.Any())
            {
                qry = qry.Filter(string.Join(" and ", filters));
            }

            qry = qry.Top(model.PageSize);
            #endregion

            var qryRes = await qry.GetAsync();

            #region MapResult
            var nextPageUrl = qryRes.NextPageRequest
                              ?.GetHttpRequestMessage()
                              ?.RequestUri
                              ?.AbsoluteUri
                              ?.ToString();

            var students = qryRes.Select(x => new AzureUserDTO(x));
            #endregion

            return(new SearchStudentsRS(students, nextPageUrl));
        }
Esempio n. 2
0
 public async Task <ActionResult <SearchStudentsRS> > SearchStudentsAsync([FromBody] SearchStudentsRQ body)
 => await _msGraph.SearchStudentsAsync(body);