public List <Campground> ListCampgrounds(int parkSelected)
        {
            List <Campground> campgroundsList = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand(SQL_GetCampsites, connection);

                    cmd.Parameters.AddWithValue("@park_id", parkSelected);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground c          = new Campground();
                        int        open       = Convert.ToInt32(reader["open_from_mm"]);
                        string     openMonth  = c.ToMonth(open);
                        int        close      = Convert.ToInt32(reader["open_to_mm"]);
                        string     closeMonth = c.ToMonth(close);

                        c.CampgroundId   = Convert.ToInt32(reader["campground_id"]);
                        c.ParkName       = Convert.ToString(reader["pname"]);
                        c.CampgroundName = Convert.ToString(reader["name"]);
                        c.OpenMonth      = openMonth;
                        c.CloseMonth     = closeMonth;
                        c.DailyFee       = Convert.ToDouble(reader["daily_fee"]);

                        campgroundsList.Add(c);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }

            return(campgroundsList);
        }
Ejemplo n.º 2
0
        public CampSearch RetrieveInfo(int id)
        {
            try
            {
                CampSearch c = new CampSearch();

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

                    SqlCommand cmd = new SqlCommand(SQL_PopulateSiteInfo, connection);

                    cmd.Parameters.AddWithValue("@campground_id", id);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground cg         = new Campground();
                        int        open       = Convert.ToInt32(reader["open_from_mm"]);
                        string     openMonth  = cg.ToMonth(open);
                        int        close      = Convert.ToInt32(reader["open_to_mm"]);
                        string     closeMonth = cg.ToMonth(close);

                        c.CampgroundId     = id;
                        c.CampgroundName   = Convert.ToString(reader["name"]);
                        c.OpenMonth        = openMonth;
                        c.OpenMonthNumber  = open;
                        c.CloseMonth       = closeMonth;
                        c.CloseMonthNumber = close;
                        c.DailyFee         = Convert.ToDouble(reader["daily_fee"]);
                    }

                    return(c);
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
        }