예제 #1
0
        public ActionResult Index([Bind(Include = "CityName")] WeatherMashupViewModel model)
        {
            //TODO FIX ENTITY FRAMEWORK BUG:
            //Entity Framework: “Store update, insert, or delete statement affected an unexpected number of rows(0)"
            try
            {
                if (ModelState.IsValid)
                {
                    model.Locations = _service.getLocation(model.CityName);

                    //If there's more than one location, let the user pick.
                    if (model.HasLocations && model.Count > 1)
                    {
                        return(View("Index", model));
                    }
                    //If locations isn't empty, it contains one location, so show it to user.
                    else if (model.HasLocations && model.Count == 1)
                    {
                        return(RedirectToAction("ShowWeather", "WeatherMashup", new { PositionID = model.Locations.First().LocationID }));
                    }
                    //Otherwise there's no matches, show message to user
                    FlashMessage.Danger("No locations where found.");
                }
                return(View("Index"));
            }
            //something's gone wrong, catch and show to user.
            catch (Exception e)
            {
                FlashMessage.Danger("Unable to find requested location.Please check your spelling.");
            }

            return(View("Index", model));
        }
예제 #2
0
 //
 //GET ShowWeather
 public ActionResult ShowWeather(int?positionID)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (!positionID.HasValue)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
             WeatherMashupViewModel model = new WeatherMashupViewModel();
             model.Weather = _service.getWeather((int)positionID);
             return(View("Index", model));
         }
     }
     //something's gone wrong, catch and show to user.
     catch (Exception e)
     {
         FlashMessage.Danger("Unable to find requested weather data.Please check your spelling.");
     }
     return(View(""));
 }