public LocalWeather GetLocalWeather(LocalWeatherInput input) { // create URL based on input paramters string apiURL = ApiBaseURL + "weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&num_of_days=" + input.num_of_days + "&date=" + input.date + "&fx=" + input.fx + "&cc=" + input.cc + "&includelocation=" + input.includelocation + "&show_comments=" + input.show_comments + "&callback=" + input.callback + "&key="+FreeAPIKey; // get the web response string result = RequestHandler.Process(apiURL); // serialize the json output and parse in the helper class LocalWeather lWeather = (LocalWeather)new JavaScriptSerializer().Deserialize(result, typeof(LocalWeather)); return lWeather; }
public PartialViewResult Weather(string text) { if (string.IsNullOrWhiteSpace(text)) { return this.PartialView("_weatherPartial", new Current_Condition()); } var input = new LocalWeatherInput(); input.query = text; input.num_of_days = "2"; input.format = "JSON"; var api = new FreeAPI(); var localWeather = api.GetLocalWeather(input); Current_Condition weatherModel = null; if (localWeather.data.current_Condition != null) { weatherModel = localWeather.data.current_Condition.FirstOrDefault(); } return this.PartialView("_weatherPartial", weatherModel ?? new Current_Condition()); }