예제 #1
0
        /// <summary>
        /// Returns a list of <see cref="Campground"/>s from a SQL database based on the given <paramref name="parkId"/>.
        /// </summary>
        /// <param name="parkId">the <see cref="Park.Id"/> the list of <see cref="Campground"/>s refer to.</param>
        /// <returns><see cref="IList{T}"/> of campgrounds.</returns>
        public IList <Campground> GetCampgrounds(int parkId)
        {
            List <Campground> campgrounds = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE park_id = @parkId;", conn);
                    cmd.Parameters.AddWithValue("@parkId", parkId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground camp = this.ConvertReaderToCampground(reader);
                        campgrounds.Add(camp);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error has occured retrieving the campgrounds from the database.");
                Console.WriteLine(ex.Message);
                throw;
            }

            return(campgrounds);
        }
예제 #2
0
        private void CreateReservation(Campground campground)
        {
            menus.MenuTitle(" Reservation Menu ");

            List <string> reservationList = menus.CampgroundReservation(campground);

            string command = Console.ReadLine();

            bool exit = false;

            while (!exit)
            {
                if (command == "s" || command == "S")
                {
                    DisplayAvailableSitesBySelectedCampground(campground, reservationList[0], reservationList[1]);
                }
                else if (command == "q" || command == "Q")
                {
                    menus.QuitMenu();
                    exit = true;
                }
                else
                {
                    menus.InvalidEntry();
                }

                Console.ReadKey();
                Console.Clear();
            }
        }
예제 #3
0
        public Campground GetCampgroundById(int campgroundId)
        {
            Campground campground = new Campground();


            return(campground);
        }
예제 #4
0
        //method campgrounds
        public List <Campground> GetCampgrounds(Park park)
        {
            List <Campground> output = new List <Campground>();

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


                    SqlCommand cmd = new SqlCommand(SQL_GetCampgrounds, conn);
                    cmd.Parameters.AddWithValue("@park", park.parkId);

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Campground camp = CampgroundFromSql(reader);
                        output.Add(camp);
                    }
                }
            }

            catch (SqlException)
            {
                throw;
            }
            return(output);
        }
        /// <summary>
        /// Add campgrounds within specified park to a list for display
        /// </summary>
        /// <param name="parkId"></param>
        /// <returns></returns>
        public List <Campground> GetCampgrounds(int parkId)
        {
            List <Campground> campgrounds = new List <Campground>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string query = CampgroundSelectQuery;

                SqlCommand command = connection.CreateCommand();
                command.CommandText = query;

                command.Parameters.AddWithValue("@park_id", parkId);

                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    DateTimeFormatInfo dateTimeFormatInfo = new DateTimeFormatInfo();
                    Campground         campground         = new Campground();
                    campground.Campground_Id = Convert.ToInt32(reader["campground_id"]);
                    campground.Park_Id       = Convert.ToInt32(reader["park_id"]);
                    campground.Name          = reader["name"] as string;
                    campground.Open_From_MM  = dateTimeFormatInfo.GetMonthName(Convert.ToInt32(reader["open_from_mm"]));
                    campground.Open_To_MM    = dateTimeFormatInfo.GetMonthName(Convert.ToInt32(reader["open_to_mm"]));
                    campground.Daily_Fee     = Convert.ToDecimal(reader["daily_fee"]);

                    campgrounds.Add(campground);
                }
            }

            return(campgrounds);
        }
        public List <Campground> GetCampgrounds(int park_id)
        {
            List <Campground> CampgroundOutput = new List <Campground>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "SELECT * FROM Campground WHERE park_id=@park_id";
                    cmd.Parameters.AddWithValue("@park_id", park_id);
                    cmd.Connection = connection;
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Campground currentCampground = new Campground();
                        currentCampground.Campground_id = int.Parse(Convert.ToString(reader["campground_id"]));
                        currentCampground.Park_id       = int.Parse(Convert.ToString(reader["park_id"]));
                        currentCampground.Name          = Convert.ToString(reader["name"]);
                        currentCampground.Open_from_mm  = int.Parse(Convert.ToString(reader["open_from_mm"]));
                        currentCampground.Open_to_mm    = int.Parse(Convert.ToString(reader["open_to_mm"]));
                        currentCampground.Daily_fee     = double.Parse(Convert.ToString(reader["daily_fee"]));
                        CampgroundOutput.Add(currentCampground);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(CampgroundOutput);
        }
        public Campground GetCampgroundById(int campgroundId)
        {
            Campground campground = null;

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string     sql = "Select * from campground where campground_id = @campgroundId";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@campgroundId", campgroundId);

                    SqlDataReader rdr = cmd.ExecuteReader();

                    if (rdr.Read())
                    {
                        campground = RowToObject(rdr);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine($"Sorry there was an Error. Message {ex.Message}");
            }
            return(campground);
        }
예제 #8
0
        public List <Campground> GetCampground(int parkId)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_Getcampgrounds, conn);

                    cmd.Parameters.AddWithValue("@parkid", parkId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground campground = new Campground();

                        campground.CampgroundId = Convert.ToInt32(reader["campground_id"]);
                        campground.ParkId       = Convert.ToInt32(reader["park_id"]);
                        campground.Name         = Convert.ToString(reader["name"]);
                        campground.OpenMonth    = Convert.ToInt32(reader["open_from_mm"]);
                        campground.ClosingMonth = Convert.ToInt32(reader["open_to_mm"]);
                        campground.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);

                        campgrounds.Add(campground);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(campgrounds);
        }
예제 #9
0
        public Campground GetCampgroundById(int campgroundId)
        {
            Campground c = null;

            try
            {
                using (SqlConnection conn = new SqlConnection(connecetionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("Select * from campground where campground_id = @campground_id", conn);
                    cmd.Parameters.AddWithValue("@campground_id", campgroundId);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        c = GetCampgroundFromReader(reader);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }

            return(c);
        }
예제 #10
0
        public Campground GetCampgroundByName(string name, string connectionString)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(@"SELECT * FROM campground 
                                                      WHERE campground.name = @campname", conn);
                    cmd.Parameters.AddWithValue("@campname", name);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground campground = new Campground();

                        campground.CampgroundID = Convert.ToInt32(reader["campground_id"]);
                        campground.Name         = Convert.ToString(reader["name"]);
                        campground.OpenFromDate = Convert.ToInt32(reader["open_from_mm"]);
                        campground.OpenToDate   = Convert.ToInt32(reader["open_to_mm"]);
                        campground.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);

                        return(campground);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
            return(null);
        }
예제 #11
0
        public List <Campground> GetCampgrounds(Park park, string connectionString)
        {
            List <Campground> camps = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground JOIN park ON park.park_id = campground.park_id WHERE park.name = @park", conn);
                    cmd.Parameters.AddWithValue("@park", park.Name);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground c = new Campground();

                        c.CampgroundID = Convert.ToInt32(reader["campground_id"]);
                        c.Name         = Convert.ToString(reader["name"]);
                        c.OpenFromDate = Convert.ToInt32(reader["open_from_mm"]);
                        c.OpenToDate   = Convert.ToInt32(reader["open_to_mm"]);
                        c.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);

                        camps.Add(c);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(camps);
        }
        public Campground GetCampground(int campground_id)
        {
            Campground campground = new Campground();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE campground_id = @campground_id", conn);
                    cmd.Parameters.AddWithValue("@campground_id", campground_id);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        campground = ConvertReaderToCampground(reader);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occured while searching camgrounds.");
                Console.WriteLine(ex.Message);
            }
            return(campground);
        }
        public IList <Campground> GetAllCampgrounds(int parkId)
        {
            List <Campground> campgrounds = new List <Campground>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE park_id =@parkId;", conn);
                    cmd.Parameters.AddWithValue("@parkId", parkId);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Campground campground = ConvertReaderToCampground(reader);
                        campgrounds.Add(campground);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occured while searching camgrounds.");
                Console.WriteLine(ex.Message);
            }
            return(campgrounds);
        }
예제 #14
0
 public IList <Site> ViewCampsites(int campgroundId, DateTime startDate, DateTime endDate)
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             connection.Open();
             SqlCommand    command = new SqlCommand("select TOP 5 site_id, max_occupancy, accessible, max_rv_length, utilities, daily_fee, name from site s JOIN campground c ON c.campground_id = s.campground_id", connection);
             SqlDataReader reader  = command.ExecuteReader();
             List <Site>   sites   = new List <Site>();
             while (reader.Read())
             {
                 Site       site       = new Site();
                 Campground campground = new Campground();
                 site.SiteId       = Convert.ToInt32(reader["site_id"]);
                 site.MaxOccupancy = Convert.ToInt32(reader["max_occupancy"]);
                 site.Accessible   = Convert.ToBoolean(reader["accessible"]);
                 site.MaxRvLength  = Convert.ToInt32(reader["max_rv_length"]);
                 site.Utilities    = Convert.ToBoolean(reader["utilities"]);
                 //TODO how to add daily fee
                 site.DailyFee = Convert.ToDecimal(reader["daily_fee"]);
                 sites.Add(site);
             }
             return(sites);
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         throw;
     }
 }
        public /*IList<Campground>*/ Campground SelectCampground(int campgroundId)
        {
            List <Campground> campground = new List <Campground>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand cmd = new SqlCommand("select * from campground where campground_Id = @campgroundId;", connection);
                    cmd.Parameters.AddWithValue("@campgroundId", campgroundId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground campgrounds = ConvertReaderToCampground(reader);
                        return(campgrounds);
                        //campground.Add(campgrounds);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occurred while selecting campground.");
                Console.WriteLine(ex.Message);
                throw;
            }
            return(null);
        }
예제 #16
0
        public List <Campground> GetCampGroundsList(int parkId)
        {
            List <Campground> output = new List <Campground>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connecetionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("Select * from campground where park_id = @park_id", conn);
                    cmd.Parameters.AddWithValue("@park_id", parkId);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Campground c = GetCampgroundFromReader(reader);
                        output.Add(c);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(output);
        }
        public Campground GetCampground(int id)
        {
            Campground campground = new Campground();

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

                    // Create the command for the sql statement
                    string     sql = "Select * from campground where campground_id = @campground_id";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@campground_id", id);
                    // Execute the query and get the result set in a reader
                    SqlDataReader rdr = cmd.ExecuteReader();

                    if (rdr.Read())
                    {
                        campground = RowToObject(rdr);
                    }
                }
            }
            catch (SqlException ex)
            {
                ErrorLog.LogError(ex);
                throw;
            }

            return(campground);
        }
예제 #18
0
        public IList <Campground> GetCampgroundByParkId(int park_Id)
        {
            List <Campground> campgrounds = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand("Select * from campground where park_id = @park_id", conn);
                    cmd.Parameters.AddWithValue("@park_id", park_Id);

                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        Campground campground = ConvertReadertoCampground(rdr);
                        campgrounds.Add(campground);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occurred communicating with the database. ");
                Console.WriteLine(ex.Message);
                throw;
            }
            return(campgrounds);
        }
        public IList <Campground> GetAllCampgrounds(int parkId)
        {
            IList <Campground> campgrounds = new List <Campground>();
            {
                try
                {
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        conn.Open();

                        string     sql = "Select * from campground where park_id = @parkId";
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        cmd.Parameters.AddWithValue("@parkId", parkId);
                        SqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            Campground campground = RowToObject(rdr);
                            campgrounds.Add(campground);
                        }
                    }
                }
                catch (SqlException ex)
                {
                    System.Console.WriteLine("An error occured." + ex);
                }
                return(campgrounds);
            }
        }
        public List <Campground> GetCampGroundsInPark(int parkId)
        {
            List <Campground> campgrounds = new List <Campground>();

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

                const string sqlParkCommand = "SELECT campground_id, park_id, name, open_from_mm, open_to_mm, daily_fee From CampGround.dbo.campground where park_id = @parkid;";
                SqlCommand   cmd            = new SqlCommand();
                cmd.CommandText = sqlParkCommand;
                cmd.Parameters.AddWithValue("@parkid", parkId);
                cmd.Connection = connection;

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Campground campground = new Campground();

                    campground.Id       = Convert.ToInt32(reader["campground_id"]);
                    campground.Park_Id  = Convert.ToInt32(reader["park_id"]);
                    campground.Name     = Convert.ToString(reader["name"]);
                    campground.OpenFrom = Convert.ToInt32(reader["open_from_mm"]);
                    campground.OpenTo   = Convert.ToInt32(reader["open_to_mm"]);
                    campground.DailyFee = Convert.ToDouble(reader["daily_fee"]);

                    campgrounds.Add(campground);
                }
            }
            return(campgrounds);
        }
        /// <summary>
        /// The override of ExecuteSelection handles whatever selection was made by the user.
        /// This is where any business logic is executed.
        /// </summary>
        /// <param name="choice">"Key" of the user's menu selection</param>
        /// <returns></returns>
        protected override bool ExecuteSelection(string choice)
        {
            switch (choice)
            {
            case "1":     // Do whatever option 1 is

                int campgroundChoice = CLIMenu.GetInteger($"Which Campground?");
                if (campgroundChoice > 0 && campgroundChoice <= park.Campgrounds.Count)
                {
                    Campground campground = park.Campgrounds[campgroundChoice - 1];
                    campground.Sites = siteDao.GetSiteId(campground.CampgroundId);

                    string arrivalDate   = CLIMenu.GetString("What is your arrival date? (yyyy-mm-dd)");
                    string departureDate = CLIMenu.GetString("What is your departure date?(yyyy-mm-dd)");


                    SiteMenu siteMenu = new SiteMenu(park, campground, siteDao, reservationDao, arrivalDate, departureDate);
                    siteMenu.Run();
                }
                else
                {
                    Console.WriteLine("That campsite is not in our database.");
                }

                Pause("");
                return(true);

            case "2":     // Do whatever option 2 is
                WriteError("When this option is complete, we will exit this submenu by returning false from the ExecuteSelection method.");
                Pause("");
                return(false);
            }
            return(true);
        }
        public List <Campground> GetAllCampGrounds()
        {
            List <Campground> output = new List <Campground>();

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

                const string SQL_getCampgrounds = "Select * from campground;";

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = SQL_getCampgrounds;
                cmd.Connection  = connection;

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Campground CampgroundsList = new Campground();

                    CampgroundsList.Id       = Convert.ToInt32(reader["campground_id"]);
                    CampgroundsList.Park_Id  = Convert.ToInt32(reader["park_id"]);
                    CampgroundsList.Name     = Convert.ToString(reader["name"]);
                    CampgroundsList.OpenFrom = Convert.ToInt32(reader["open_from_mm"]);
                    CampgroundsList.OpenTo   = Convert.ToInt32(reader["open_to_mm"]);
                    CampgroundsList.DailyFee = Convert.ToDouble(reader["daily_fee"]);

                    output.Add(CampgroundsList);
                }

                return(output);
            }
        }
예제 #23
0
        /// <summary>
        /// Gets the list of campgrounds by park id.
        /// </summary>
        /// <param name="parkID">The id of the park.</param>
        /// <returns>campgrounds</returns>
        public IList <Campground> GetAllCampgroundsByPark(int parkID)
        {
            List <Campground> campgrounds = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand("select * from campground where park_id = @park_id;", conn);
                    cmd.Parameters.AddWithValue("@park_id", parkID);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground campground = ConvertReaderToCampground(reader);
                        campgrounds.Add(campground);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Error retreiving parks");
                Console.WriteLine(ex.Message);
            }

            return(campgrounds);
        }
예제 #24
0
        public IList <Campground> GetCampgrounds(int parkId)
        {
            List <Campground> campgrounds = new List <Campground>();

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    conn.Open();
                    SqlCommand    cmd    = new SqlCommand($"Select * from campground where park_id = {parkId} order by name asc", conn);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground e = GetCampgroundFromReader(reader);
                        campgrounds.Add(e);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(campgrounds);
        }
예제 #25
0
        /// <summary>
        /// Finds all campsites on the campgrounds that are available to be reserved in the given timeframe
        /// </summary>
        /// <param name="campground">Specified campground</param>
        /// <param name="StartDate">Desired reservation start date</param>
        /// <param name="EndDate">Desired reservation end date</param>
        /// <returns>A list of campsites available for reservation</returns>
        public List <Site> SearchAvailableReservations(Campground campground, DateTime StartDate, DateTime EndDate)
        {
            var sitelist        = GetAllSitesInCampground(campground);
            var reservationList = GetReservations(campground);

            var filteredSiteList = new List <Site>();

            foreach (Site site in sitelist)
            {
                bool resAvailable = true;
                foreach (Reservation reservation in reservationList)
                {
                    if (((StartDate >= reservation.FromDate && StartDate <= reservation.ToDate) ||
                         (EndDate >= reservation.FromDate && EndDate <= reservation.ToDate)) &&
                        reservation.SiteID == site.SiteID)
                    {
                        resAvailable = false;
                    }
                }
                if (resAvailable && filteredSiteList.Count < 5)
                {
                    filteredSiteList.Add(site);
                }
            }
            return(filteredSiteList);
        }
예제 #26
0
        //Display park information
        public string DisplayCampgroundInformation(int park_id)
        {
            Campground campground = new Campground();

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

                    SqlCommand cmd = new SqlCommand($"SELECT * FROM campground where campground_id = @park_id", connection);
                    cmd.Parameters.AddWithValue("@park_id", park_id);
                    SqlDataReader reader = cmd.ExecuteReader();


                    while (reader.HasRows)
                    {
                        campground.Campground_Id = Convert.ToInt32(reader["Campground_Id"]);
                        campground.Name          = Convert.ToString(reader["Name"]);
                        campground.Open_From_MM  = Convert.ToInt32(reader["Open_From_MM"]);
                        campground.Open_To_MM    = Convert.ToInt32(reader["Open_To_MM"]);
                        campground.Daily_Fee     = Convert.ToDecimal(reader["Daily_Fee"]);

                        Console.WriteLine($"Campground ID{campground.Campground_Id} Name {campground.Name} Open From {campground.Open_From_MM} Closed {campground.Open_To_MM} Daily Fee {campground.Daily_Fee}");
                    }
                    return($"");
                }
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.Message);
            }

            return($"nothing");
        }
        public List <CampSite> GetCampSitesInCampGround(Campground campground)
        {
            List <CampSite> campSites = new List <CampSite>();

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

                const string sqlParkCommand = "SELECT [site_id],[campground_id],[site_number],[max_occupancy],[accessible],[max_rv_length],[utilities] FROM [ParkReservation].[dbo].[site] where campground_id = @campgroundID";
                SqlCommand   cmd            = new SqlCommand();
                cmd.Parameters.AddWithValue("@campgroundId", campground.CampgroundId);
                cmd.CommandText = sqlParkCommand;
                cmd.Connection  = connection;

                //Pull data off the table
                SqlDataReader reader = cmd.ExecuteReader();

                //Looping through the table and populating the list with all the rows
                while (reader.Read())
                {
                    CampSite campsite = new CampSite();

                    campsite.Id           = Convert.ToInt32(reader["site_id"]);
                    campsite.CampgroundId = Convert.ToInt32(reader["campground_id"]);
                    campsite.SiteNumber   = Convert.ToInt32(reader["site_number"]);
                    campsite.MaxOccupancy = Convert.ToInt32(reader["max_occupancy"]);
                    campsite.Accesible    = Convert.ToBoolean(reader["accessible"]);
                    campsite.MaxRvLength  = Convert.ToInt32(reader["max_rv_length"]);
                    campsite.Utilities    = Convert.ToBoolean(reader["utilities"]);
                    campSites.Add(campsite);
                }
            }

            return(campSites);
        }
        public IList <Campground> DisplayParkCampgrounds(int parkId)
        {
            List <Campground> campground = new List <Campground>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    // ConvertReaderToCampground(reader);
                    SqlCommand cmd          = new SqlCommand();
                    string     sqlStatement = "select * from campground where park_id = @parkId";
                    cmd.Parameters.AddWithValue("@parkId", parkId);
                    cmd.CommandText = sqlStatement;
                    cmd.Connection  = connection;
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground campgrounds = ConvertReaderToCampground(reader);
                        campground.Add(campgrounds);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred while searching campgrounds.");
                Console.WriteLine(e.Message);
                throw;
            }
            return(campground);
        }
예제 #29
0
        public List <Campground> GetAllCampgrounds()
        {
            List <Campground> result = new List <Campground>();

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

                    SqlCommand cmd = new SqlCommand(SQL_GetAllCampgrounds, conn);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Campground c = MapResultToCampground(reader);
                        result.Add(c);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }

            return(result);
        }
예제 #30
0
        public Campground FindCampground(int campground_id)
        {
            Campground   campground = null;
            const string sql        = "SELECT * From campground WHERE campground_id = @campground_id;";

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

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@campground_id", campground_id);
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    campground = GetCampgroundFromReader(reader);
                }
            }

            if (campground == null)
            {
                throw new Exception("Campground does not exist.");
            }

            return(campground);
        }