Example #1
0
        public IActionResult SaveTempChoice(string tempScale, string parkCode)
        {
            ParkWeather parkWeather = new ParkWeather();

            parkWeather.TempScale = tempScale;
            HttpContext.Session.SetString("TempScale", tempScale);
            return(RedirectToAction("Detail", new{ parkCode }));
        }
Example #2
0
        public IActionResult Detail(string parkCode)
        {
            ParkWeather parkWeather = new ParkWeather();

            parkWeather.Park      = ParkDao.GetSelectedPark(parkCode);
            parkWeather.Weathers  = WeatherDao.GetAllWeathers(parkCode);
            parkWeather.TempScale = GetTempChoice();

            return(View(parkWeather));
        }
        public ActionResult ParkDetails(string parkID)
        {
            Park           park    = dal.GetAPark(parkID);
            List <Weather> weather = dal.GetParkWeather(parkID);
            ParkWeather    model   = new ParkWeather(park, weather);

            if (Session["tempPreference"] == null)
            {
                Session["tempPreference"] = true;
                model.isFahrenheit        = (bool)Session["tempPreference"];
            }
            else
            {
                model.isFahrenheit = (bool)Session["tempPreference"];
            }

            return(View("ParkDetails", model));
        }
 public List <ParkWeather> Parks()
 {
     using (SqlConnection conn = new SqlConnection(connectionString))
     {
         conn.Open();
         SqlCommand         command = new SqlCommand(getParkNames, conn);
         SqlDataReader      results = command.ExecuteReader();
         List <ParkWeather> parks   = new List <ParkWeather>();
         while (results.Read())
         {
             ParkWeather park = new ParkWeather();
             park.ParkName = Convert.ToString(results["parkName"]);
             park.ParkCode = Convert.ToString(results["parkCode"]);
             parks.Add(park);
         }
         return(parks);
     }
 }
Example #5
0
        public IList <ParkWeather> GetParkWeather(string parkCode)

        {
            List <ParkWeather> weather = new List <ParkWeather>();

            {
                // Create a new connection object
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    // Open the connection
                    conn.Open();

                    string sql = $"SELECT * FROM weather WHERE parkCode = @parkCode";

                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@parkCode", parkCode);
                    // Execute the command
                    SqlDataReader reader = cmd.ExecuteReader();

                    // Loop through each row
                    while (reader.Read())
                    {
                        // Create a Park
                        ParkWeather parkWeather = new ParkWeather();
                        parkWeather.ParkCode             = Convert.ToString(reader["parkCode"]);
                        parkWeather.FiveDayForecastValue = Convert.ToInt32(reader["fiveDayForecastValue"]);
                        parkWeather.Low                   = Convert.ToInt32(reader["low"]);
                        parkWeather.High                  = Convert.ToInt32(reader["high"]);
                        parkWeather.Forecast              = Convert.ToString(reader["forecast"]);
                        parkWeather.WeatherImage          = parkWeather.GetWeatherImage();
                        parkWeather.WeatherReccomendation = parkWeather.GetWeatherRec();
                        parkWeather.TempRecommendation    = parkWeather.GetTempRec();

                        weather.Add(parkWeather);
                        //weather.Add(MapRowToWeather(reader));
                    }
                }
            }
            return(weather);
        }
        /// <summary>
        /// Detail View of Parks with 5 Day weather forecast
        /// </summary>
        /// <param name="id">Park.ParkCode to GET that park upon Click()</param>
        /// <returns>Detail View</returns>
        public ActionResult Detail(string id)
        {
            // If no park was clicked then return to index page
            if (id == null)
            {
                return(RedirectToAction("Index", "Park"));
            }

            //Gets current Temp unit to work with in View
            string tempUnit = GetCurrentTempUnit();

            //Get park by param: id
            Park           park    = _parkDAL.GetPark(id);
            List <Weather> weather = _weatherDAL.GetWeatherByParkCode(id);
            ParkWeather    pw      = new ParkWeather()
            {
                Park     = park,
                Weather  = weather,
                TempUnit = tempUnit
            };

            return(View("Detail", pw));
        }
        public List <ParkWeather> GetAllParks()
        {
            List <ParkWeather> allParkWeathers = new List <ParkWeather>();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand    cmd    = new SqlCommand(getAllParksSql, conn);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ParkWeather pw = new ParkWeather();
                    pw.Acreage             = Convert.ToInt32(reader["acreage"]);
                    pw.AnnualVisitorCount  = Convert.ToInt32(reader["annualVisitorCount"]);
                    pw.Climate             = Convert.ToString(reader["climate"]);
                    pw.ElevationInFeet     = Convert.ToInt32(reader["elevationInFeet"]);
                    pw.EntryFee            = Convert.ToInt32(reader["entryFee"]);
                    pw.FiveDayForcastValue = Convert.ToInt32(reader["fiveDayForecastValue"]);
                    pw.Forecast            = Convert.ToString(reader["forecast"]);
                    pw.High = Convert.ToInt32(reader["high"]);
                    pw.InspirationalQuote       = Convert.ToString(reader["inspirationalQuote"]);
                    pw.InspirationalQuoteSource = Convert.ToString(reader["inspirationalQuoteSource"]);
                    pw.Low                   = Convert.ToInt32(reader["low"]);
                    pw.MilesOfTrail          = Convert.ToInt32(reader["milesOfTrail"]);
                    pw.NumberOfAnimalSpecies = Convert.ToInt32(reader["numberOfAnimalSpecies"]);
                    pw.NumberOfCampsites     = Convert.ToInt32(reader["numberOfCampsites"]);
                    pw.ParkCode              = Convert.ToString(reader["parkCode"]);
                    pw.ParkDescription       = Convert.ToString(reader["parkDescription"]);
                    pw.ParkName              = Convert.ToString(reader["parkName"]);
                    pw.State                 = Convert.ToString(reader["state"]);
                    pw.YearFounded           = Convert.ToInt32(reader["yearFounded"]);

                    allParkWeathers.Add(pw);
                }
            }
            return(allParkWeathers);
        }
Example #8
0
        private ParkWeather MapWeatherToProduct(SqlDataReader reader, string unit)
        {
            ParkWeather parkWeather = new ParkWeather();

            parkWeather.Park_Code            = Convert.ToString(reader["parkCode"]);
            parkWeather.FiveDayForecastValue = Convert.ToInt32(reader["fiveDayForecastValue"]);
            if (unit.ToLower() == "c")
            {
                // todo: convert
                double low = Convert.ToInt32(reader["low"]);
                parkWeather.LowTemp = (int)(((double)low - 32) / 1.8);
                double high = Convert.ToInt32(reader["high"]);
                parkWeather.HighTemp         = (int)(((double)high - 32) / 1.8);
                parkWeather.Temperature_Unit = "C";
            }
            else
            {
                parkWeather.LowTemp          = Convert.ToInt32(reader["low"]);
                parkWeather.HighTemp         = Convert.ToInt32(reader["high"]);
                parkWeather.Temperature_Unit = "F";
            }
            parkWeather.Forecast = Convert.ToString(reader["forecast"]);
            return(parkWeather);
        }