public Task <IEnumerable <Person> > GetPeople(QueryPersonParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            IEnumerable <Person> query = People.Values;

            if (parameters.FirstName?.Any() ?? false)
            {
                query = query.Where(x => parameters.FirstName.Contains(x.FirstName));
            }

            if (parameters.LastName?.Any() ?? false)
            {
                query = query.Where(x => parameters.LastName.Contains(x.LastName));
            }

            if (parameters.Id?.Any() ?? false)
            {
                query = query.Where(x => parameters.Id.Contains(x.Id));
            }

            return(Task.FromResult(query));
        }
        // created a method for GetPeople to make cleaner
        private string ParseQueryPersonParameters(QueryPersonParameters parameters)
        {
            string url = PeopleUrlBase;

            if (parameters != null)
            {
                parameters.FirstName?.ForEach(firstName =>
                {
                    url = QueryHelpers.AddQueryString(url, "firstName", firstName);
                });

                parameters.LastName?.ForEach(lastName =>
                {
                    url = QueryHelpers.AddQueryString(url, "lastName", lastName);
                });

                parameters.Id?.ForEach(id =>
                {
                    url = QueryHelpers.AddQueryString(url, "id", id.ToString());
                });
            }
            return(url);
        }
Ejemplo n.º 3
0
 public Task <IEnumerable <Person> > GetPeople([FromQuery] QueryPersonParameters parameters)
 {
     return(_repository.GetPeople(parameters));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Invokes the http api to return one or more people that match the query parameters.
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public Task <IEnumerable <Person> > GetPeople(QueryPersonParameters parameters)
 {
     // Implementation goes here!
     throw new NotImplementedException();
 }
        /// <summary>
        /// Invokes the http api to return one or more people that match the query parameters.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Person> > GetPeople(QueryPersonParameters parameters)
        {
            var stream = _httpClient.GetStreamAsync(ParseQueryPersonParameters(parameters));

            return(await JsonSerializer.DeserializeAsync <List <Person> >(await stream));
        }