public ActionResult NewDetails(int id = 0, string message = null)
        {
            if (Request.IsAuthenticated)
            {
                try
                {
                    var placeService = new PlaceService2();

                    MyPlace myweather = mpr.GetWeather(id);
                    string  place     = myweather.place;
                    string  region    = myweather.region;

                    ExtWeather extWeather = placeService.GetWeatherInfo(place, region);
                    extWeather.placeName = myweather.place;

                    ViewBag.longitude = myweather.longitude;
                    ViewBag.latitude  = myweather.latitude;

                    if (myweather == null)
                    {
                        return(RedirectToAction("Error", "NotFound"));
                    }
                    ViewBag.UserMessage = "";
                    return(View(extWeather));
                }
                catch
                {
                    string userMessage = "Sidan kunde inte hämtas pga problem hos extern service";
                    return(RedirectToAction("Index", "MyPlaces", new { message = userMessage }));
                }
            }
            return(RedirectToAction("LogIn", "Account"));
        }
        public ActionResult NewCreateConfirm([Bind(Include = "Place")] ViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                var place        = model.place;
                var placeService = new PlaceService2();
                var regions      = placeService.GetRegions(place);
                if (regions.Count == 0)
                {
                    string userMessage = "Vi kunde inte hitta någon region där din sökta plats finns";
                    return(RedirectToAction("NewCreate", "MyPlaces", new { message = userMessage }));
                }

                ViewData["regions"] = regions;
                return(View());
            }
            return(RedirectToAction("LogIn", "Account"));
        }
        public ActionResult NewCreate(ViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    MyPlace myweather = new MyPlace();
                    myweather.place = model.place;
                    var placeService2 = new PlaceService2();

                    var username = User.Identity.Name;
                    var place    = myweather.place;
                    var region   = model.region;
                    //Prova att istället här kalla på GetWeatherlist

                    List <MyPlace> weatherlist = new List <MyPlace>();
                    //Weatherlist kollar om användaren redan har platsen.
                    weatherlist = mpr.GetWeatherlist(username, place, region);
                    int number = weatherlist.Count;
                    if (number > 0)
                    {
                        string userMessage = "Din post har inte sparats eftersom platsen redan finns";
                        return(RedirectToAction("Index", "MyPlaces", new { message = userMessage }));
                    }

                    bool exists = placeService2.CheckExistanceYr(place, region);
                    if (exists == false)
                    {
                        //Platsen finns inte
                        string userMessage = "Din post har inte sparats eftersom platsen inte finns på vädersidan";
                        return(RedirectToAction("NewCreate", "MyPlaces", new { message = userMessage }));
                    }

                    var newCoordinates = placeService2.GetNewCoordinates(place, region);

                    if (newCoordinates == null) // || newCoordinates.Count == 0
                    {
                        string userMessage = "Din post har inte sparats eftersom platsen inte finns på geonames";
                        return(RedirectToAction("NewCreate", "MyPlaces", new { message = userMessage }));
                    }

                    //Ska flyttas in i ovanstående if-sats.
                    if (newCoordinates.Count == 0)
                    {
                        return(RedirectToAction("NewCreate", "MyPlaces"));
                    }

                    myweather.longitude   = decimal.Parse(newCoordinates[0], System.Globalization.CultureInfo.InvariantCulture);
                    myweather.latitude    = decimal.Parse(newCoordinates[1], System.Globalization.CultureInfo.InvariantCulture);
                    myweather.region      = region;
                    myweather.projectuser = username;


                    mpr.CreateWeather(myweather);
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            return(RedirectToAction("LogIn", "Account"));
        }