public async void Init(CityWeatherData info) { _imageProvider = DependencyService.Get <IImageProvider>(); SettingsCommand = new Command(OnSettingsButtonClicked); DateTime now = DateTime.Now.ToLocalTime(); TimeSpan t = now - Utilities.GetTime(info.LastUpdateTime); if (t.TotalHours > AppConstants.Values.MAX_UPDATE_TIME_DIFF) { NetworkAdapter nd = new NetworkAdapter(); var dt = await nd.GetCurreentWeatherInfo(info.CityId.ToString()); info = CityWeatherData.FromApiData(dt); } Temperature = string.Format(AppConstants.Strings.CELSIUS_FORMAT, Utilities.KelvinToCelcius(info.Temperature)); City = string.Format(AppConstants.Strings.CITY_FORMAT, info.CityName, info.CountryName); MainWeatherImage = _imageProvider.GetImagePath(App.Database.GetWeatherIcon(info.MainWeatherImageId)); WeatherDescription = info.WeatherInfo; LocalTime = string.Format(AppConstants.Strings.LAST_UPDATE_FORMAT, Utilities.GetFormattedTime(info.LastUpdateTime)); Sunrise = string.Format(AppConstants.Strings.SUNRISE_FORMAT, Utilities.GetFormattedTime(info.SunriseTime)); Sunset = string.Format(AppConstants.Strings.SUNSET_FORMAT, Utilities.GetFormattedTime(info.SunsetTime)); Humidity = string.Format(AppConstants.Strings.HUMIDITY_FORMAT, info.Humidity); Pressure = string.Format(AppConstants.Strings.PRESSURE_FORMAT, info.Pressure); Wind = string.Format(AppConstants.Strings.WIND_FORMAT, info.Wind); }
public void TestGetWeatherAPI() { //Arrange MockWeatherDataService mockService = new MockWeatherDataService(); WeatherDataController service = new WeatherDataController(mockService); CityWeatherData sydneyData = new CityWeatherData { Wind = "Strong", Pressure = "1008 hpa", SkyCondition = "Clear", Temperature = 31.3, Time = DateTime.Now.ToString(), Visibility = "Good" }; //Act var result = service.GetWeather("Australia", "Sydney") as OkObjectResult; var response = result.Value as CityWeatherData; //Asset Assert.AreEqual(sydneyData, response); }
private void OnAddButtonClicked() { if (null == _autosuggestBox.Text || string.IsNullOrEmpty(_autosuggestBox.Text)) { App.Current.MainPage.DisplayAlert(AppConstants.Strings.ERROR_TITLE, AppConstants.Strings.ERROR_NULL_CITY, AppConstants.Strings.DIALOG_CLOSE); return; } CityDataModel cityModel = null; string cityName = ""; if (_autosuggestBox.Text.Contains(",")) { var tmp = _autosuggestBox.Text.Split(','); cityName = tmp[0]; } else { cityName = _autosuggestBox.Text; } foreach (var ct in _lastSuggestion) { if (ct.City.Equals(cityName)) { cityModel = ct; break; } } if (null != cityModel) { CityWeatherData dt = new CityWeatherData() { CityId = cityModel.CityId, CityName = cityModel.City, CountryName = cityModel.Country }; App.Current.MainPage.DisplayAlert(AppConstants.Strings.DIALOG_INFO, AppConstants.Strings.DIALOG_CITY_ADDED, AppConstants.Strings.DIALOG_OK); App.Database.AddUserWeatherData(dt); _navigation.PopModalAsync(); } else { App.Current.MainPage.DisplayAlert(AppConstants.Strings.ERROR_TITLE, AppConstants.Strings.ERROR_INCORRECT_CITY, AppConstants.Strings.DIALOG_CLOSE); return; } }
public void UpdateUserWeatherData(CityWeatherData data) { try { var tmpData = database.Table <CityWeatherData>().Where(i => i.CityId == data.CityId).FirstOrDefault(); if (null != tmpData) { database.Update(data); } else { AddUserWeatherData(data); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
public CurrentWeatherViewModel(CityWeatherData info, INavigation navigation) { _navigation = navigation; Init(info); }