public ActionResult GeoLocation(double?latitude, double?longitude) { if (string.IsNullOrWhiteSpace(Settings.Default.ApiKey)) { #if DEBUG return(Json(WeatherSummaryViewModel.GetFailed("[Debug Build] Error details: 'ApiKey' setting is not configured. Please specify API Key in Web.config."))); #else return(Json(WeatherSummaryViewModel.GetFailed())); #endif } if (!latitude.HasValue || !longitude.HasValue) { return(Json(WeatherSummaryViewModel.GetFailed())); } try { using (ForecastClient client = new ForecastClient()) { string url = BuildUrl(Settings.Default.BaseUrl, Settings.Default.ApiKey, latitude.Value, longitude.Value); WeatherSummary weatherSummary = client.Load(url); return(Json(new WeatherSummaryViewModel(weatherSummary, HttpContext, new IconRepository()))); } } catch (Exception ex) { #if DEBUG return(Json(WeatherSummaryViewModel.GetFailed("[Debug Build] Error details: " + ex.Message))); #else return(Json(WeatherSummaryViewModel.GetFailed())); #endif } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); ForecastClient.Dispose(); }