async void OnFetchButtonClicked(object sender, EventArgs e)
        {
            PersonRepository.Root personResponse = await _personRestService.GetPersonsAsync(Constants.RandomUserEndPoint);

            List <Person> persons = new List <Person>();

            for (int i = 0; i < personResponse.Results.Count; i++)
            {
                persons.Add(new Person
                {
                    Name      = personResponse.Results[i].Name.First,
                    Lastname  = personResponse.Results[i].Name.Last,
                    Thumbnail = personResponse.Results[i].Picture.Thumbnail
                });
            }

            collectionView.ItemsSource = persons;
        }
Exemplo n.º 2
0
        public async Task <PersonRepository.Root> GetPersonsAsync(string uri)
        {
            PersonRepository.Root person = new PersonRepository.Root();
            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    person = JsonConvert.DeserializeObject <PersonRepository.Root>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(person);
        }