/// <summary>
        /// Returns an Json, and is used by graph.js
        /// </summary>
        /// <returns></returns>
        public ActionResult GetTempData()
        {
            var model = new WeatherIndexViewModel
            {
                LocationInput = (string)Session[SessionLocation]
            };
            model.LocationObject = model.WeatherService.GetLocation(model.LocationInput);

            var temp = from t in model.Weather
                       select new { day = model.DayOfWeek(t.ValidTime), temp = t.Temperature };

            return Json(temp, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
 public ActionResult Index([Bind(Include = "ScreenName")] WeatherIndexViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var city = _service.GetCity(model.ScreenName);
             _service.RefreshWeathers(city);
             model.City = city;
         }
     }
     catch (Exception ex)
     {
         while (ex.InnerException != null)
         {
             ex = ex.InnerException;
         }
         ModelState.AddModelError(String.Empty, ex.Message);
     }
     return(View(model));
 }
        // GET:
        public ActionResult Index()
        {
            //Kalmar will be shown if user is not logged in
            var location = "Kalmar";

            //If user is logged in and have saved a default location
            if (User.Identity.Name != String.Empty)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                if (user != null)
                {
                    location = user.DefaultLocation;
                }
            }

            var model = new WeatherIndexViewModel
            {
                LocationInput = location
            };

            model.LocationObject = model.WeatherService.GetLocation(model.LocationInput);
            Session[SessionLocation] = model.LocationInput;
            return View(model);
        }
        public virtual ActionResult Index(FormCollection collection)
        {
            var model = new WeatherIndexViewModel();

            if (TryUpdateModel(model, new[] { "LocationInput" }, collection))
            {
                try
                {
                    model.LocationObject = model.WeatherService.GetLocation(model.LocationInput);
                    Session[SessionLocation] = model.LocationInput;
                }
                catch (GeoLocationNotFoundException)
                {
                    //Shows an error if location is not found
                    ModelState.AddModelError("LocationNotFound", "Platsen hittades inte");
                }

            }
            model.LocationInput = (string)Session[SessionLocation];
            model.LocationObject = model.WeatherService.GetLocation(model.LocationInput);

            model.LocationInput = (string)Session[SessionLocation];

            return View(model);
        }