public ActionResult Detail(string parkCode, string scale)
        {
            if (parkCode == null)
            {
                parkCode = Session["ParkCode"] as string;
                if (parkCode == null)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                Session["ParkCode"] = parkCode;
            }

            if (scale != null)
            {
                Session["Scale"] = scale;
            }
            Parks          park         = new Parks();
            List <Weather> parkForecast = new List <Weather>();

            park         = _dal.GetSpecificPark(parkCode);
            parkForecast = _dal.GetForecast(parkCode);
            Tuple <Parks, List <Weather> > parkWithForecast = new Tuple <Parks, List <Weather> >(park, parkForecast);

            return(View("Detail", parkWithForecast));
        }
Esempio n. 2
0
        public IActionResult Parks()
        {
            APIHandler webHandler = new APIHandler();
            Parks      results    = webHandler.GetData();

            return(View(results));
        }
Esempio n. 3
0
        async Task ExecuteLoadParksCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Parks.Clear();
                var items = await DataStore.GetItemsAsync(true);

                foreach (var item in items)
                {
                    Parks.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        /// <summary>
        /// Method to receive data from API end point as a collection of objects
        ///
        /// JsonConvert parses the JSON string into classes
        /// </summary>
        /// <returns></returns>
        public Parks GetParks()
        {
            string NATIONAL_PARK_API_PATH = BASE_URL + "/parks?limit=20";
            string parksData = "";

            Parks parks = null;

            httpClient.BaseAddress = new Uri(NATIONAL_PARK_API_PATH);

            // It can take a few requests to get back a prompt response, if the API has not received
            //  calls in the recent past and the server has put the service on hibernation
            try
            {
                HttpResponseMessage response = httpClient.GetAsync(NATIONAL_PARK_API_PATH).GetAwaiter().GetResult();
                if (response.IsSuccessStatusCode)
                {
                    parksData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                }

                if (!parksData.Equals(""))
                {
                    // JsonConvert is part of the NewtonSoft.Json Nuget package
                    parks = JsonConvert.DeserializeObject <Parks>(parksData);
                }
            }
            catch (Exception e)
            {
                // This is a useful place to insert a breakpoint and observe the error message
                Console.WriteLine(e.Message);
            }

            return(parks);
        }
        /// <summary>
        /// Gets information on a specific park from Park table in NationalParkForecast DB
        /// </summary>
        /// <param name="parkId"></param>
        /// <returns>Park object</returns>
        public Parks GetSpecificPark(string parkId)
        {
            Parks        park       = new Parks();
            const string getParkSql = "SELECT * FROM park WHERE parkCode = @parkCode;";

            try
            {
                using (SqlConnection conn = new SqlConnection(_connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(getParkSql, conn);
                    cmd.Parameters.AddWithValue("@parkCode", parkId);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        park = GetSinglePark(reader);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(park);
        }
        public IActionResult Parks()
        {
            APIHandler webHandler = new APIHandler();
            Parks      parks      = webHandler.GetParks();

            return(View(parks));
        }
Esempio n. 7
0
        public List <Parks> GetParks()
        {
            List <Parks> output = new List <Parks>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand    cmd    = new SqlCommand("Select * From Park ORDER BY name", conn);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Parks p = new Parks();
                        p.Id          = Convert.ToInt32(reader["park_id"]);
                        p.Name        = Convert.ToString(reader["name"]);
                        p.Location    = Convert.ToString(reader["location"]);
                        p.Established = Convert.ToDateTime(reader["establish_date"]);
                        p.Area        = Convert.ToInt32(reader["area"]);
                        p.Visitors    = Convert.ToInt32(reader["visitors"]);
                        p.Description = Convert.ToString(reader["description"]);
                        output.Add(p);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(output);
        }
        static string API_KEY  = "BMY3pb3vdn5TKtuyxdaXuMoUXYbJN3ix20DBW3fU"; //Add your API key here inside ""
        public IActionResult Index()
        {
            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Add("X-Api-Key", API_KEY);
            httpClient.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            string NATIONAL_PARK_API_PATH = BASE_URL + "/parks?limit=20";
            string parksData = "";
            Parks  parks     = null;

            try
            {
                HttpResponseMessage response = httpClient.GetAsync(NATIONAL_PARK_API_PATH).GetAwaiter().GetResult();
                if (response.IsSuccessStatusCode)
                {
                    parksData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                }

                if (!parksData.Equals(""))
                {
                    // JsonConvert is part of the NewtonSoft.Json Nuget package
                    parks = JsonConvert.DeserializeObject <Parks>(parksData);
                }
            }
            catch (Exception e)
            {
                // This is a useful place to insert a breakpoint and observe the error message
                Console.WriteLine(e.Message);
            }
            return(View(parks));
        }
Esempio n. 9
0
        public bool AddPark(Parks p)
        {
            connection();
            SqlCommand com = new SqlCommand("AddNewParkDetails", con);

            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@id", p.id);
            com.Parameters.AddWithValue("@states", p.states);
            com.Parameters.AddWithValue("@latLong", p.latLong);
            com.Parameters.AddWithValue("@description", p.description);
            com.Parameters.AddWithValue("@designation", p.designation);
            com.Parameters.AddWithValue("@parkCode", p.parkCode);
            com.Parameters.AddWithValue("@directionsInfo", p.directionsInfo);
            com.Parameters.AddWithValue("@directionsUrl", p.directionsUrl);
            com.Parameters.AddWithValue("@fullName", p.fullName);
            com.Parameters.AddWithValue("@url", p.url);
            com.Parameters.AddWithValue("@weatherInfo", p.weatherInfo);
            com.Parameters.AddWithValue("@name", p.name);

            con.Open();
            int i = com.ExecuteNonQuery();

            if (i >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 10
0
        public void OnGet()
        {
            using (var webClient = new WebClient())
            {
                //Consuming Parks data
                string crimesJSON = webClient.DownloadString("https://raw.githubusercontent.com/JMFrank215/IS7024Project/master/Parks_Data.txt");
                var    parks      = Parks.FromJson(crimesJSON);
                ViewData["Parks"] = parks;
                ParkSpace.Parks[] Parksparks = ParkSpace.Parks.FromJson(crimesJSON);


                //Consuming Crime data
                string jsonString = webClient.DownloadString("https://raw.githubusercontent.com/JMFrank215/IS7024Project/master/PDI_Crime_Data.txt");


                //Validation received data
                string  crimeschema = System.IO.File.ReadAllText("CrimeSchema.json");
                JSchema cschema     = JSchema.Parse(crimeschema);

                JArray cjsonObject = JArray.Parse(jsonString);

                if (cjsonObject.IsValid(cschema))
                {
                    var crimes = Crime.FromJson(jsonString);
                    ViewData["Crime"] = crimes;
                }
            }
        }
Esempio n. 11
0
        public ActionResult Detail(string id)
        {
            ParkSqlDAL dal       = new ParkSqlDAL(connectionString);
            Parks      parkModel = dal.GetPark(id);

            ViewBag.weather = id;

            return(View("Detail", parkModel));
        }
Esempio n. 12
0
        public IActionResult SearchByName(String parkName)
        {
            Parks allParks = null;

            if (!String.IsNullOrEmpty(parkName))
            {
                allParks = SearchPark("q=" + parkName);
            }
            return(View(allParks));
        }
Esempio n. 13
0
        public void GetParkTest_name()
        {
            Parks result = new Parks();

            ParkSqlDAL parks = new ParkSqlDAL(connectionString);

            result = parks.GetPark("ENP");

            Assert.AreEqual("Everglades National Park", result.Name);
        }
Esempio n. 14
0
        public void GetParkTest_climate()
        {
            Parks result = new Parks();

            ParkSqlDAL parks = new ParkSqlDAL(connectionString);

            result = parks.GetPark("ENP");

            Assert.AreEqual("Tropical", result.Climate);
        }
Esempio n. 15
0
        public IActionResult SearchByState(String stateCode)
        {
            Parks allParks = null;

            if (!String.IsNullOrEmpty(stateCode))
            {
                allParks = SearchPark("stateCode=" + stateCode);
            }
            return(View(allParks));
        }
Esempio n. 16
0
        private Parks GetParksFromReader(SqlDataReader reader)
        {
            Parks item = new Parks();

            item.ParkId        = Convert.ToInt32(reader["park_id"]);
            item.Name          = Convert.ToString(reader["name"]);
            item.Location      = Convert.ToString(reader["location"]);
            item.EstablishDate = Convert.ToDateTime(reader["establish_date"]);
            item.Area          = Convert.ToInt32(reader["area"]);
            item.Visitors      = Convert.ToInt32(reader["visitors"]);
            item.Description   = Convert.ToString(reader["description"]);
            return(item);
        }
Esempio n. 17
0
        public IActionResult RemoveFromBucketList(int id)
        {
            var       FullList = new Parks();
            UserParks found    = _context.UserParks.Where(x => x.UsersParkIds == id).First();

            if (found != null)
            {
                _context.UserParks.Remove(found);
                _context.SaveChanges();
            }

            return(RedirectToAction("DisplayBucketList"));
        }
Esempio n. 18
0
        public void OnGet()
        {
            using (var webClient = new WebClient())
            {
                //Consuming Weather data
                String key           = "4aa3dc52539246b7a6911f057001e696";
                String weatherString = webClient.DownloadString("https://api.weatherbit.io/v2.0/current?&city=Cincinnati&country=USA&key=" + key);
                WeatherSpace.Weather weatherWeather = WeatherSpace.Weather.FromJson(weatherString);

                //precipitation
                long precip = 0;
                foreach (WeatherSpace.Datum weather in weatherWeather.Data)
                {
                    precip = weather.Precip;
                }
                if (precip < 1)
                {
                    ViewData["WeatherMessage"] = "Not looking like rain!";
                }
                else
                {
                    ViewData["WeatherMessage"] = "Rain expected, be careful out there!";
                }

                //Consuming Parks data
                string crimesJSON = webClient.DownloadString("https://raw.githubusercontent.com/JMFrank215/IS7024Project/master/Parks_Data.txt");
                var    parks      = Parks.FromJson(crimesJSON);
                ViewData["Parks"] = parks;
                ParkSpace.Parks[] Parksparks = ParkSpace.Parks.FromJson(crimesJSON);


                //Consuming Crime data
                string jsonString = webClient.DownloadString("https://raw.githubusercontent.com/JMFrank215/IS7024Project/master/PDI_Crime_Data.txt");


                //Validation received data
                string  crimeschema = System.IO.File.ReadAllText("CrimeSchema.json");
                JSchema cschema     = JSchema.Parse(crimeschema);

                JArray cjsonObject = JArray.Parse(jsonString);

                if (cjsonObject.IsValid(cschema))
                {
                    var crimes = Crime.FromJson(jsonString);
                    ViewData["Crime"] = crimes;
                }
            }
        }
Esempio n. 19
0
        public IList <Parks> GetParks()
        {
            IList <Parks> parks = new List <Parks>();

            try
            {
                // TODO 01 Create the connection
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    // TODO 02 Open Connection
                    connection.Open();
                    // TODO 03
                    SqlCommand sqlCommand = new SqlCommand();
                    // TODO 04 Create command text
                    string sqlStatement = "select * from park";
                    // TODO 05 Set command text to command
                    sqlCommand.CommandText = sqlStatement;
                    // TODO 06 Set Connection
                    sqlCommand.Connection = connection;
                    // TODO 07 Read data
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    // Read each row
                    while (reader.Read())
                    {
                        Parks park = new Parks();

                        park.ParkId          = Convert.ToInt32(reader["park_id"]);
                        park.ParkName        = Convert.ToString(reader["name"]);
                        park.Location        = Convert.ToString(reader["location"]);
                        park.EstablishedDate = Convert.ToDateTime(reader["establish_date"]);
                        park.Area            = Convert.ToInt32(reader["area"]);
                        park.Visitors        = Convert.ToInt32(reader["visitors"]);
                        park.Description     = Convert.ToString(reader["description"]);
                        parks.Add(park);
                    }
                    // TODO 08 Close the connection via the using statement
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred retrieving list of parks.");
                Console.WriteLine(e.Message);
            }
            return(parks);
        }
Esempio n. 20
0
        public IList <Parks> GetParks()
        {
            List <Parks> result = new List <Parks>();
            const string sql    = "SELECT * FROM dbo.park;";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd    = new SqlCommand(sql, conn);
                var        reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Parks park = GetParksFromReader(reader);
                    result.Add(park);
                }
            }
            return(result);
        }
Esempio n. 21
0
        public Parks GetPark(string id)
        {
            Parks pk = new Parks();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlCommand cmd = new SqlCommand("SELECT * FROM park WHERE parkCode = @park_id AND parkCode IS NOT NULL;", connection);
                    cmd.Parameters.AddWithValue("@park_id", id);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Parks pr = new Parks();
                        pr.ParkCode       = Convert.ToString(reader["parkCode"]);
                        pr.State          = Convert.ToString(reader["state"]);
                        pr.Name           = Convert.ToString(reader["parkName"]);
                        pr.Acres          = Convert.ToInt32(reader["acreage"]);
                        pr.Elevation      = Convert.ToInt32(reader["elevationInFeet"]);
                        pr.TrailMiles     = Convert.ToDouble(reader["milesOfTrail"]);
                        pr.NumCampSites   = Convert.ToInt32(reader["numberOfCampsites"]);
                        pr.Climate        = Convert.ToString(reader["climate"]);
                        pr.YearFounded    = Convert.ToInt32(reader["yearFounded"]);
                        pr.AnnualVisitors = Convert.ToInt32(reader["annualVisitorCount"]);
                        pr.Quote          = Convert.ToString(reader["inspirationalQuote"]);
                        pr.QuoteAuthor    = Convert.ToString(reader["inspirationalQuoteSource"]);
                        pr.Description    = Convert.ToString(reader["parkDescription"]);
                        pr.EntryFee       = Convert.ToInt32(reader["entryFee"]);
                        pr.AnimalSpecies  = Convert.ToInt32(reader["numberOfAnimalSpecies"]);

                        pk = pr;
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Unable to retrieve park data, please try again at a later time.");
            }
            return(pk);
        }
Esempio n. 22
0
        public IActionResult Parks()
        {
            APIHandler webHandler = new APIHandler();
            Parks      parks      = webHandler.GetParks();

            foreach (Park park in parks.data)
            {
                //Database will give PK constraint violation error when trying to insert record with existing PK.
                //So add company only if it doesnt exist, check existence using symbol (PK)
                if (dbContext.Parks.Where(p => p.id.Equals(park.id)).Count() == 0)
                {
                    dbContext.Parks.Add(park);
                }
            }

            dbContext.SaveChanges();

            return(View(parks));
        }
Esempio n. 23
0
        public List <Parks> GetAllParks()
        {
            List <Parks> parks = new List <Parks>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("SELECT * FROM park ORDER BY parkName ASC", conn);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Parks p = new Parks();
                        p.ParkCode       = Convert.ToString(reader["parkCode"]);
                        p.State          = Convert.ToString(reader["state"]);
                        p.Name           = Convert.ToString(reader["parkName"]);
                        p.Acres          = Convert.ToInt32(reader["acreage"]);
                        p.Elevation      = Convert.ToInt32(reader["elevationInFeet"]);
                        p.TrailMiles     = Convert.ToDouble(reader["milesOfTrail"]);
                        p.NumCampSites   = Convert.ToInt32(reader["numberOfCampsites"]);
                        p.Climate        = Convert.ToString(reader["climate"]);
                        p.YearFounded    = Convert.ToInt32(reader["yearFounded"]);
                        p.AnnualVisitors = Convert.ToInt32(reader["annualVisitorCount"]);
                        p.Quote          = Convert.ToString(reader["inspirationalQuote"]);
                        p.QuoteAuthor    = Convert.ToString(reader["inspirationalQuoteSource"]);
                        p.Description    = Convert.ToString(reader["parkDescription"]);
                        p.EntryFee       = Convert.ToInt32(reader["entryFee"]);
                        p.AnimalSpecies  = Convert.ToInt32(reader["numberOfAnimalSpecies"]);

                        parks.Add(p);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Unable to retrieve park data, please try again at a later time.");
            }
            return(parks);
        }
Esempio n. 24
0
        static string API_KEY  = "9QzH6Eaz2ePobL2iN091lq7H0fZr9PRZq9C7heMR";    //Venkata API Key from https://www.nps.gov/subjects/developer/get-started.htm

        public IActionResult Index()
        {
            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Add("X-Api-Key", API_KEY);     // Is X-Api-Key  same for all? or standard?
            httpClient.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            string NATIONAL_PARK_API_URL = BASE_URL + "/parks?;  //?limit=20";   // limit = 20 is to limit accepting 20 records in each call to the api
            string parksData             = "";

            Parks parks = null;

            httpClient.BaseAddress = new Uri(NATIONAL_PARK_API_URL);

            try
            {
                HttpResponseMessage response = httpClient.GetAsync(NATIONAL_PARK_API_URL).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    parksData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                }

                if (!parksData.Equals(""))
                {
                    parks = JsonConvert.DeserializeObject <Parks>(parksData);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            return(View(parks));
//            return View();
        }
Esempio n. 25
0
        public IActionResult Chart()
        {
            Parks parks = SearchPark(null);
            Dictionary <String, int> parkCountByState = new Dictionary <string, int>();

            foreach (Park park in parks.data)
            {
                String[] stateCodes = park.states.Split(",");
                foreach (String stateCode in stateCodes)
                {
                    if (parkCountByState.ContainsKey(stateCode))
                    {
                        parkCountByState[stateCode] = parkCountByState[stateCode] + 1;
                    }
                    else
                    {
                        parkCountByState.Add(stateCode, 1);
                    }
                }
            }


            string[] chartColors = new string[] { "rgb(255, 99, 132)", "rgb(255, 159, 64)", "rgb(255, 205, 86)", "rgb(75, 192, 192)",
                                                  "rgb(54, 162, 235)", "rgb(153, 102, 255)", "rgb(201, 203, 207)", "#4dc9f6",
                                                  "#f67019", "#f53794", "#537bc4", "#acc236", "#166a8f", "#00a950", "#58595b", "#8549ba" };
            Chart Model = new Chart
            {
                chartType        = "doughnut",
                labels           = String.Join(",", parkCountByState.Keys.Select(d => "'" + d + "'")),
                data             = String.Join(",", parkCountByState.Values.Select(d => d)),
                chartTitle       = "No. of parks by state",
                backgroundColors = String.Join(",", chartColors.Select(d => "'" + d + "'"))
            };

            return(View(Model));
        }
Esempio n. 26
0
        /// <summary>
        /// Parses CSV for GameLog files found here: http://www.retrosheet.org/gamelogs/index.html
        /// A description of the fields is here: http://www.retrosheet.org/gamelogs/glfields.txt
        /// </summary>
        /// <param name="file"></param>
        public void LoadGameLog(string file)
        {
            using (var fs = new FileStream(file, FileMode.Open))
            {
                using (var reader = new StreamReader(fs))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        try
                        {
                            var parts = line.Split(',');

                            var game = new Game();

                            // 0: Date
                            game.Date = parts[0].RemoveQuotes().ToDate();

                            // 3-4: Visiting team, league
                            var team   = parts[3].RemoveQuotes();
                            var league = parts[4].RemoveQuotes();

                            Team visitor = null;
                            if (!Teams.TryGetValue(team, out visitor))
                            {
                                visitor = new Team {
                                    Name = team, League = league.ToLeague()
                                };
                            }
                            game.Visitor = visitor;

                            // 6-7: Homee team, league
                            team   = parts[6].RemoveQuotes();
                            league = parts[7].RemoveQuotes();
                            Team home = null;
                            if (!Teams.TryGetValue(team, out home))
                            {
                                home = new Team {
                                    Name = team, League = league.ToLeague()
                                };
                                Teams.Add(home.Name, home);
                            }
                            game.Home = home;

                            // 9-10: Score
                            game.VisitorScore = int.Parse(parts[9]);
                            game.HomeScore    = int.Parse(parts[10]);

                            // 16-17: Park id, attendance
                            Park park   = null;
                            var  parkId = parts[16].RemoveQuotes();
                            if (!Parks.TryGetValue(parkId, out park))
                            {
                                park = new Park {
                                    Id = parkId
                                };
                                Parks.Add(parkId, park);
                            }
                            game.Park = park;

                            game.Attendance = int.Parse(parts[17]);

                            Games.Add(game);
                        }
                        catch
                        {
                            // ignore any parsing errors.
                        }
                    }
                }
            }
        }
Esempio n. 27
0
 public void addPark(Parks p)
 {
     parksList.Add(p);
 }
Esempio n. 28
0
 public void removePark(Parks p)
 {
     parksList.Remove(p);
 }