Example #1
0
        /// <summary>
        /// Downloads the API data to a List
        /// </summary>
        /// <returns></returns>
        private async Task LoadFromAPI()
        {
            try
            {
                apiConnection = new APIConnection();

                //gets data from the API
                var response = await apiConnection.GetApiData("http://restcountries.eu", "/rest/v2/all");

                //if data is unsuccessfull for some reason(internet connection problems/api down)
                if (!response.Success)
                {
                    throw new Exception(response.Answer);
                }
                //loads the result on to the Countries list
                Countries = (List <Country>)response.Result;

                response = await apiConnection.GetRates();

                CurrencyConverter.Rates = (List <Rate>)response.Result;

                CurrencyConverter.AddEuro();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }