Example #1
0
        /// <summary>
        /// Gets a single Park object by its Park Code
        /// </summary>
        /// <param name="parkCode">Park Code</param>
        /// <returns>Park object</returns>
        public Park GetPark(string parkCode)
        {
            Park park = new Park();

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                string getParkSQL = "SELECT * FROM park " +
                                    "WHERE parkCode = @parkCode;";

                SqlCommand cmd = new SqlCommand(getParkSQL, conn);
                cmd.Parameters.AddWithValue("@parkCode", parkCode);

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    park = GetParkFromReader(reader);
                }
            }

            return(park);
        }
Example #2
0
        /// <summary>
        /// Retrieves a single selected park information
        /// </summary>
        /// <returns></returns>
        public Park GetOnePark(string parkCode)
        {
            Park park = new Park();

            string getPark = @"select * from park WHERE parkCode = @parkCode;";

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = getPark;
                cmd.Connection  = conn;
                cmd.Parameters.AddWithValue("@parkCode", parkCode);

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    park = MapRowToParks(reader);
                }
            }

            return(park);
        }
Example #3
0
        public Park getParkIdData(string parkCode)
        {
            Park currentPark = new Park();

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    conn.Open();
                    SqlCommand command = new SqlCommand(getParkIdSqlCommand, conn);
                    string     sql     = @"'" + parkCode + @"'";
                    command.Parameters.AddWithValue("@parkCode", parkCode);
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        currentPark.Acreage                  = Convert.ToInt32(reader["acreage"]);
                        currentPark.AnnualVisitorCount       = Convert.ToInt32(reader["annualVisitorCount"]);
                        currentPark.Climate                  = Convert.ToString(reader["climate"]);
                        currentPark.ElevationInFeet          = Convert.ToInt32(reader["elevationInFeet"]);
                        currentPark.InspirationalQuoteSource = Convert.ToString(reader["inspirationalQuoteSource"]);
                        currentPark.MilesOfTrail             = Convert.ToUInt32(reader["milesOfTrail"]);
                        currentPark.NumberOfAnimalSpecies    = Convert.ToInt32(reader["numberOfAnimalSpecies"]);
                        currentPark.NumberOfCampsites        = Convert.ToInt32(reader["numberOfCampsites"]);
                        currentPark.ParkCode                 = Convert.ToString(reader["parkCode"]);
                        currentPark.ParkName                 = Convert.ToString(reader["parkName"]);
                        currentPark.State       = Convert.ToString(reader["state"]);
                        currentPark.YearFounded = Convert.ToInt32(reader["yearFounded"]);
                    }
                }
                return(currentPark);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
        public Park GetSelectedPark(string parkCode)
        {
            Park park = new Park();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("SELECT * from park WHERE parkCode = @parkCode;");
                    cmd.Connection = conn;
                    cmd.Parameters.AddWithValue("@parkCode", parkCode);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        park = ConvertReaderToPark(reader);
                    }
                }
            } catch (Exception e)
            {
                throw;
            }
            return(park);
        }
Example #5
0
        public List <Park> GetAllParks()
        {
            List <Park> result = new List <Park>();

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = SQL_GetAllParks;
                cmd.Connection  = conn;

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Park park = new Park();
                    park.ParkCode              = Convert.ToString(reader["parkCode"]);
                    park.ParkName              = Convert.ToString(reader["parkName"]);
                    park.State                 = Convert.ToString(reader["state"]);
                    park.Acreage               = Convert.ToInt32(reader["acreage"]);
                    park.ElevationInFeet       = Convert.ToInt32(reader["elevationInFeet"]);
                    park.MilesOfTrail          = Convert.ToDouble(reader["milesOfTrail"]);
                    park.NumberOfCampSites     = Convert.ToInt32(reader["numberOfCampsites"]);
                    park.Climate               = Convert.ToString(reader["climate"]);
                    park.YearFounded           = Convert.ToInt32(reader["yearFounded"]);
                    park.AnnualVisitorCount    = Convert.ToInt32(reader["annualVisitorCount"]);
                    park.InspirationalQuote    = Convert.ToString(reader["inspirationalQuote"]);
                    park.QuoteSource           = Convert.ToString(reader["inspirationalQuoteSource"]);
                    park.ParkDescription       = Convert.ToString(reader["parkDescription"]);
                    park.EntryFee              = Convert.ToInt32(reader["entryFee"]);
                    park.NumberOfAnimalSpecies = Convert.ToInt32(reader["numberOfAnimalSpecies"]);
                    result.Add(park);
                }
            }
            return(result);
        }
Example #6
0
        //single park
        public Park GetPark(string parkCode)
        {
            Park park = new Park();

            try
            {
                // Create a new connection object
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    // Open the connection
                    conn.Open();
                    //SQL statement with parameter
                    string sql = $"SELECT * FROM park where parkCode = @parkCode";
                    //sql command object to use statement
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    //binding parameter to park code passed in
                    cmd.Parameters.AddWithValue("@parkCode", parkCode);

                    // Execute the command
                    SqlDataReader reader = cmd.ExecuteReader();

                    // Loop through each row
                    park = null;
                    while (reader.Read())
                    {
                        // Create a park
                        park = RowToObject(reader);
                    }
                    return(park);
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
        }
Example #7
0
        public Park GetPark(string parkCode)
        {
            Park park = new Park();

            return(GetParks().FirstOrDefault(p => p.ParkCode == parkCode));
        }
Example #8
0
        public Park GetParkDetails(string parkCode)
        {
            Park p = new Park();

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

                    SqlCommand cmd = new SqlCommand(SQL_GetParkDetails, conn);
                    cmd.Parameters.AddWithValue("@parkCode", parkCode);

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        p.ParkCode              = Convert.ToString(reader["parkCode"]);
                        p.ParkName              = Convert.ToString(reader["parkName"]);
                        p.State                 = Convert.ToString(reader["state"]);
                        p.Acreage               = Convert.ToInt32(reader["acreage"]);
                        p.Elevation             = Convert.ToInt32(reader["elevationInFeet"]);
                        p.MilesOfTrail          = Convert.ToDouble(reader["milesOfTrail"]);
                        p.NumberOfCampsite      = 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.QuoteSource           = Convert.ToString(reader["inspirationalQuoteSource"]);
                        p.Description           = Convert.ToString(reader["parkDescription"]);
                        p.EntryFee              = Convert.ToInt32(reader["entryFee"]);
                        p.NumberOfAnimalSpecies = Convert.ToInt32(reader["numberOfAnimalSpecies"]);
                    }

                    reader.Close();

                    cmd = new SqlCommand(SQL_GetAllForecasts, conn);
                    cmd.Parameters.AddWithValue("@parkCode", parkCode);

                    reader = cmd.ExecuteReader();

                    List <Forecast> forecasts = new List <Forecast>();

                    while (reader.Read())
                    {
                        Forecast f = new Forecast();

                        f.WeatherForecast = Convert.ToString(reader["forecast"]);
                        f.DayNumber       = Convert.ToInt32(reader["fiveDayForecastValue"]);
                        f.LowTemperature  = Convert.ToInt32(reader["low"]);
                        f.HighTemperature = Convert.ToInt32(reader["high"]);

                        forecasts.Add(f);
                    }

                    p.FiveDayForecasts = forecasts;
                }
            }
            catch (SqlException ex)
            {
                //Log and throw the exception
                throw new NotImplementedException();
            }

            return(p);
        }