public ActionResult Weather() { WeatherInfo.RootObject wi = new WeatherInfo.RootObject(); wi = GetWeather(); ViewBag.temp = wi.timeSeries[1].parameters[1].values[0]; ViewBag.dag = wi.timeSeries[1].parameters[4].values[0]; ViewBag.tid = wi.timeSeries[1].validTime; return(View(wi.timeSeries.ToList())); }
public WeatherInfo.RootObject GetWeather() { string url = "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/20.263035/lat/63.825847/data.json"; WebClient webClient = new WebClient() { Encoding = Encoding.UTF8 }; string result = webClient.DownloadString(url); WeatherInfo.RootObject weatherInfo = new WeatherInfo.RootObject(); weatherInfo = JsonConvert.DeserializeObject <WeatherInfo.RootObject>(result); return(weatherInfo); }
public async Task <WeatherInfo.RootObject> GetWeather(string cityName) { WeatherInfo.RootObject result = null; try { var url = BaseUrl + cityName + UrlQueryString; var json = await httpClient.GetAsync(url); if (json.IsSuccessStatusCode) { var jsonContent = await json.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <WeatherInfo.RootObject>(jsonContent); } } catch (System.Exception) { } return(result); }
public ActionResult Spela(string searchString) { WeatherInfo.RootObject wi = new WeatherInfo.RootObject(); wi = GetWeather(); ViewBag.temp = wi.timeSeries[2].parameters[1].values[0]; ViewBag.vind = wi.timeSeries[2].parameters[4].values[0]; ViewBag.tid = wi.timeSeries[2].validTime; if (Session["användarID"] == null) { return(Redirect("/Login.aspx")); } int userID = Int32.Parse(Session["användarID"].ToString()); if ((from s in db.GameRound where s.Game1.Active == 1 && s.Game1.Player == userID select s).FirstOrDefault() != null) { int unfinishedID = ((from s in db.GameRound where s.Game1.Active == 1 && s.Game1.Player == userID select s).OrderBy(o => o.Hole1.Number)).FirstOrDefault().ID; return(RedirectToAction("PlayRound", new { id = unfinishedID })); } SelectCourse selectCourse = new SelectCourse(); selectCourse.Courses = db.GolfCourse.ToList(); selectCourse.Location = new SelectList(db.GolfCourse.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()), "Location", "Location"); selectCourse.Courses = db.GolfCourse.ToList(); selectCourse.Name = new SelectList(db.GolfCourse, "ID", "Name"); var golfCourses = from s in db.GolfCourse select s; if (!String.IsNullOrEmpty(searchString)) { golfCourses = golfCourses.Where(s => s.Location.Contains(searchString)); } ViewBag.Locations = new SelectList(db.GolfCourse, "Name", "Location"); return(View(selectCourse)); }