/// <summary> /// get all weather data from the weather service ( current & forecast) /// map data with our view models /// </summary> public async Task BuildCompleteViewModel() { //check internet connection IsConnected = AppHelper.CheckInternet(); if (IsConnected) { var configuration = appServices.GetConfiguration(); if (string.IsNullOrEmpty(configuration.lastUserLocation)) { AlertChanged(ResourcesValues.LocationUnkonwenMessage); UserDialogs.Instance.HideLoading(); return; } try { //pull complete weather data rootModel = await weatherService.GetRootModel(configuration.APIKey, int.Parse(configuration.numberOfDays) + 1, configuration.lastUserLocation); var dailyAstro = rootModel.forecast.forecastday[0].astro; // daily weather mapping _dailyViewModel.textcolor = configuration.textcolor; _dailyViewModel.regionAndCity = $"{rootModel.location.region}, {rootModel.location.name}"; _dailyViewModel.country = $"{rootModel.location.country}, Today"; _dailyViewModel.temperature = $"{rootModel.current.temp_c.ToString()}{AppConstants.celsius}"; _dailyViewModel.icon = $"{AppConstants.httpStart}{rootModel.current.condition.icon}"; _dailyViewModel.condition = rootModel.current.condition.text; _dailyViewModel.feelLike = $"Feel Like {rootModel.current.feelslike_c.ToString()}{AppConstants.celsius}"; _dailyViewModel.humidity = $"{rootModel.current.humidity.ToString()} {AppConstants.persent}"; _dailyViewModel.minMaxTemp = $"{rootModel.current.temp_c.ToString()} {AppConstants.celsius}"; _dailyViewModel.wind = $"{rootModel.current.wind_kph.ToString()} {AppConstants.wind}"; _dailyViewModel.wind = $"{rootModel.current.wind_kph.ToString()} {AppConstants.wind}"; _dailyViewModel.backgroundImage = AppHelper.CheckDayState(rootModel.location.localtime, dailyAstro.sunrise, dailyAstro.sunset); // weekly weather mapping _forecastViewModel.Clear(); foreach (var item in rootModel.forecast.forecastday.Skip(1)) { _forecastViewModel.Add(new ForecastWeatherViewModel(configuration.textcolor, $"{item.day.mintemp_c.ToString()}{AppConstants.celsius}" , $"{item.day.maxtemp_c.ToString()}{AppConstants.celsius}" , AppHelper.GetDayOfWeek(item.date) , $"{AppConstants.httpStart}{item.day.condition.icon}") ); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Track objecy mapping error: {ex.Message}"); AlertChanged(ResourcesValues.tryAgainLaterMessage); } } else { AlertChanged(ResourcesValues.CheckInternetMessage); } }