public IActionResult Detail(string parkCode, bool?changeTemp)
        {
            if (changeTemp != null)
            {
                SetSessionData <bool>("IsFahrenheit", !GetSessionData <bool>("IsFahrenheit"));
            }

            DetailViewModel vm = new DetailViewModel();

            vm.Park = _db.GetNationalPark(parkCode);

            IList <ParkWeatherItem> weatherItems = _weatherDb.GetWeatherForPark(parkCode);

            foreach (var weatherItem in weatherItems)
            {
                WeatherViewItem weathView = new WeatherViewItem();
                weathView.Day       = weatherItem.Day;
                weathView.DayOfWeek = DateTime.Today.AddDays(weatherItem.Day - 1).DayOfWeek.ToString();
                weathView.Forecast  = weatherItem.Forecast;
                weathView.High      = weatherItem.High;
                weathView.Low       = weatherItem.Low;
                weathView.SetImageSrc();
                weathView.SetRecommendations();
                if (!GetSessionData <bool>("IsFahrenheit"))
                {
                    weathView.ConvertToCelsius();
                }
                vm.Weather.Add(weathView);
            }

            return(GetAuthenticatedView("Detail", vm));
        }
Exemplo n.º 2
0
        public void TestGetNationalPark()
        {
            var result = _db.AddNewNationalPark(_nationalParkItem);

            //park successfully added
            Assert.IsTrue(result);

            var retreivedPark = _db.GetNationalPark(_nationalParkItem.ParkCode);

            Assert.AreEqual(_nationalParkItem, retreivedPark);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Detail(string parkCode)
        {
            NationalPark park  = NPD.GetNationalPark(parkCode);
            string       lat   = park.Latitude;
            string       longi = park.Longitude;

            //List <Weather> weatherForPark = WD.GetWeather(parkCode);
            Datum2[] arrayOfWeathers = null;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://api.darksky.net/");
                //HTTP GET
                var responseTask = client.GetAsync($"forecast/8763304943d537b219b0eae054152e90/{lat},{longi}");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    string content = await result.Content.ReadAsStringAsync();

                    arrayOfWeathers = JsonConvert.DeserializeObject <Rootobject>(content).daily.data;
                }
            }


            for (int i = 0; i < arrayOfWeathers.Length - 1; i++)
            {
                Weather w = new Weather();
                w.Low             = Convert.ToInt32(arrayOfWeathers[i].temperatureLow);
                w.High            = Convert.ToInt32(arrayOfWeathers[i].temperatureHigh);
                w.Forecast        = (arrayOfWeathers[i].icon);
                w.FiveDayForecast = i + 1;
                w.ParkCode        = parkCode;
                park.forecasts.Add(w);
            }

            //park.forecasts = arrayOfWeathers;
            ViewData["user_preferences"] = GetUserPreferences();
            return(View("Detail", park));
        }