// Note - The Xamarin.Forms Previewer requires a default, parameterless constructor to render a page. public CurrentWeatherPage() { InitializeComponent(); viewModel = new CurrentWeatherViewModel(); BindingContext = viewModel; }
async Task LoadWeatherAsync() { SetInitialState(); var currentWeather = await _weatherService.GetCurrentAsync(); if (currentWeather != null) { DataContext = new CurrentWeatherViewModel(this, currentWeather); ToggleContentVisibility(true); _fadeIn.Begin(); } }
public MainPage() { InitializeComponent(); ViewModel = new CurrentWeatherViewModel(); MainRelativeLayout.Children.Add(InformationStack, Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, InformationStack) / 2), Constraint.RelativeToParent(parent => parent.Height / 2 - getHeight(parent, InformationStack) / 1.7)); double getWidth(RelativeLayout parent, View view) => view?.Measure(parent.Width, parent.Height).Request.Width ?? -1; double getHeight(RelativeLayout parent, View view) => view?.Measure(parent.Width, parent.Height).Request.Height ?? -1; }
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args) { var item = args.SelectedItem as City; if (item == null) { return; } // Manually deselect item ItemsListView.SelectedItem = null; var wvm = new CurrentWeatherViewModel(); wvm.City = item.Name; await Navigation.PushAsync(new CurrentWeatherPage(wvm)); }
public ActionResult UpdateCurrentWeatherView(string cityName, string countryName) { var client = new HttpClient(); var response = client.GetAsync(string.Format("{0}://{1}/api/weather/getcurrentweather/{2}/{3}", HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Authority, cityName.Replace(".", ""), countryName.Replace(".", ""))).Result; if (response.IsSuccessStatusCode) { var currentWeather = response.Content.ReadAsAsync <CurrentWeatherResponse>().Result; var model = new CurrentWeatherViewModel(); model.Weather = currentWeather; return(PartialView("_CurrentWeather", model)); } else { return(null); } }
async Task LoadWeatherAsync() { try { SetInitialState(); var currentWeather = await _weatherService.GetCurrentAsync(); if (!currentWeather.Equals(default(Models.Current))) { DataContext = new CurrentWeatherViewModel(this, currentWeather); ToggleContentVisibility(true); _fadeIn.Begin(); } } catch (Exception ex) when(DebugHelper.IsHandled <CurrentWeather>(ex)) { // If we're unable to load, this is probably a configuration issue. } }
public IActionResult ShowWeatherResponse() { var errorViewModel = new CurrentWeatherViewModel(); if (TempData["isCityNameEmpty"] != null && (bool)TempData["isCityNameEmpty"]) { errorViewModel.ViewErrorToken = "Invalid city name"; return(View(errorViewModel)); } TempData.Keep("Weather_Info"); var storedResults = TempData["Weather_Info"].ToString(); var apiResponseDto = JsonConvert.DeserializeObject <ProviderResult <WeatherData> >(storedResults); if (apiResponseDto.StatusCode != (int)StatusCodes.Success) { if (apiResponseDto.StatusCode == (int)StatusCodes.NotFound) { errorViewModel.ViewErrorToken = "Not found"; } else if (apiResponseDto.StatusCode == (int)StatusCodes.BadRequest) { errorViewModel.ViewErrorToken = "Invalid city name"; } else if (apiResponseDto.StatusCode == (int)StatusCodes.Conflict) { errorViewModel.ViewErrorToken = "Api limit reached"; } else if (apiResponseDto.StatusCode == (int)StatusCodes.Unauthorized) { errorViewModel.ViewErrorToken = "Api service problem"; } return(View(errorViewModel)); } var currentWeatherViewModel = _mapper.Map <CurrentWeatherViewModel>(apiResponseDto); return(View(currentWeatherViewModel)); }
public CurrentWeatherPage(CurrentWeatherViewModel viewModel) { InitializeComponent(); BindingContext = this.viewModel = viewModel; }