/// <summary>
        /// Campground menu
        /// </summary>
        /// <param name="park">The park that contains the campgrounds to be displayed</param>
        private void DisplayCampgroundMenu(ParkItem park)
        {
            var campgrounds = _db.GetCampgrounds(park.Id);

            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                DisplayColored("Park Campgrounds");
                Console.WriteLine($"{park.Name} National Park Campgrounds");
                Console.WriteLine();
                DisplayCampgrounds(campgrounds);
                Console.WriteLine();
                DisplayColored(Message_SelectCommand);
                Console.WriteLine(" (1) Search for Reservation");
                Console.WriteLine(" (B) Return to Previous Screen");
                Console.WriteLine();

                var selection = CLIHelper.GetString(Message_EnterSelection);

                if (selection.ToLower() == Option_Return)
                {
                    exit = true;
                }
                else if (selection == Option_CampgroundSearchReservation)
                {
                    DisplaySearchMenu(park, campgrounds);
                }
                else
                {
                    DisplayInvalidSelection();
                }
            }
        }
        public void Initialize()
        {
            _db   = new NationalParkSQLDAO("Data Source=localhost\\sqlexpress;Initial Catalog=NPGeek;Integrated Security=True");
            _tran = new TransactionScope();
            ParkItem park = new ParkItem
            {
                Acreage                  = 100,
                AnnualVisitorCount       = 5,
                Climate                  = "Woodland",
                ElevationInFeet          = 20,
                EntryFee                 = 500,
                InspirationalQuote       = "Money rules the world.",
                InspirationalQuoteSource = "Bill Gates",
                MilesOfTrail             = 2,
                NumberOfAnimalSpecies    = 200,
                NumberOfCampsites        = 100,
                ParkCode                 = "CASH",
                ParkDescription          = "Park for people with money.",
                ParkName                 = "The Banks",
                State       = "OH",
                YearFounded = 1800
            };

            _park = park;
        }
        /// <summary>
        /// Manages the reservation workflow for the entire park
        /// </summary>
        /// <param name="park">The park information the reservtion is for</param>
        private void DisplayParkWideReservation(ParkItem park)
        {
            ReservationInfo reservationInfo = new ReservationInfo();
            List <SiteInfo> siteInfos       = new List <SiteInfo>();

            try
            {
                reservationInfo = GetReservationInfo(reservationInfo);
                var campgrounds = _db.GetCampgrounds(park.Id);
                foreach (var campground in campgrounds)
                {
                    reservationInfo.CampgroundId = campground.Id;
                    var sites = _db.GetSites(reservationInfo);
                    foreach (var site in sites)
                    {
                        siteInfos.Add(site.CreateSiteInfo(campground.DailyFee, campground.Name));
                    }
                }

                ReservationItem item = new ReservationItem();
                item.SiteId = GetSiteSelection(siteInfos, reservationInfo, "", true);
                DisplayCompleteReservation(reservationInfo, item);
                throw new ExitToMainException();
            }
            catch (ExitException)
            {
                // do nothing, the user cancelled the reservation process
            }
        }
Пример #4
0
        public async Task <IActionResult> PutParkItem(long id, ParkItem parkItem)
        {
            if (id != parkItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(parkItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ParkItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public async Task <ActionResult <ParkItem> > PostParkItem(ParkItem parkItem)
        {
            _context.ParkItems.Add(parkItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetParkItem", new { id = parkItem.Id }, parkItem));
        }
        /// <summary>
        /// Creates a Park database object
        /// </summary>
        /// <param name="name">The name of the park</param>
        /// <returns>A completed database park object with dummy data</returns>
        private ParkItem CreatePark(string name)
        {
            var park = new ParkItem()
            {
                Area            = 10,
                Description     = "description",
                EstablishedDate = DateTime.Now,
                Location        = "Ohio",
                Name            = name,
                Visitors        = 100000
            };

            return(park);
        }
Пример #7
0
        /// <summary>
        /// Parses the sql result set into a park item object
        /// </summary>
        /// <param name="reader">The sql data reader that contains the resultset</param>
        /// <returns>Populated park item object</returns>
        private ParkItem GetParkItemFromReader(SqlDataReader reader)
        {
            ParkItem item = new ParkItem();

            item.Id              = Convert.ToInt32(reader["park_id"]);
            item.Name            = Convert.ToString(reader["name"]);
            item.Location        = Convert.ToString(reader["location"]);
            item.EstablishedDate = 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);
        }
        /// <summary>
        /// Park details menu
        /// </summary>
        /// <param name="park">The park item to be displayed</param>
        private void DisplayParkDetailsMenu(ParkItem park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                DisplayColored("Park Information Screen");
                Console.WriteLine($"{park.Name} National Park");
                Console.WriteLine($"Location:".PadRight(18) + $"{park.Location}");
                Console.WriteLine($"Established:".PadRight(18) + $"{park.EstablishedDate.ToShortDateString()}");
                Console.WriteLine($"Area:".PadRight(18) + $"{park.Area.ToString("N0")} sq km");
                Console.WriteLine($"Annual Visitors:".PadRight(18) + $"{park.Visitors.ToString("N0")}");
                Console.WriteLine();
                Console.WriteLine(park.Description);
                Console.WriteLine();
                DisplayColored(Message_SelectCommand);
                Console.WriteLine(" (1) View Campgrounds");
                Console.WriteLine(" (2) Search for Reservation");
                Console.WriteLine(" (3) View Upcoming Reservations");
                Console.WriteLine(" (B) Return to Previous Screen");
                Console.WriteLine();

                var selection = CLIHelper.GetString(Message_EnterSelection);
                if (selection == Option_Return)
                {
                    exit = true;
                }
                else if (selection == Option_ParkSearchReservation)
                {
                    DisplayParkWideReservation(park);
                }
                else if (selection == Option_ViewCampgrounds)
                {
                    DisplayCampgroundMenu(park);
                }
                else if (selection == Option_ViewUpcomingReservations)
                {
                    var reservations = _db.GetReservationsForNext30Days(park.Id);
                    DisplayReservationHistory(reservations, false);
                }
                else
                {
                    DisplayInvalidSelection();
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Adds a row to the park table
        /// </summary>
        /// <param name="park">The park item containing the data to add</param>
        /// <returns>The autogenerated primary key</returns>
        public int AddPark(ParkItem park)
        {
            const string sql = "INSERT [park] (name, location, establish_date, area, visitors, description) " +
                               "VALUES (@name, @location, @establish_date, @area, @visitors, @description);";

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

                SqlCommand cmd = new SqlCommand(sql + _getLastIdSQL, conn);
                cmd.Parameters.AddWithValue("@name", park.Name);
                cmd.Parameters.AddWithValue("@location", park.Location);
                cmd.Parameters.AddWithValue("@establish_date", park.EstablishedDate);
                cmd.Parameters.AddWithValue("@area", park.Area);
                cmd.Parameters.AddWithValue("@visitors", park.Visitors);
                cmd.Parameters.AddWithValue("@description", park.Description);
                park.Id = (int)cmd.ExecuteScalar();
            }

            return(park.Id);
        }
        /// <summary>
        /// Load Park main menu
        /// </summary>
        private void ParkMainMenu()
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                List <ParkItem> parks = _db.GetParkItems();

                Console.WriteLine("Welcome to the 100% Official National Park Registration Manager.");
                Console.WriteLine();

                try
                {
                    string [] asciiArt = Properties.Resources.ascii_mountain.Split("\n");
                    foreach (var line in asciiArt)
                    {
                        Console.WriteLine(line);
                    }
                    Console.WriteLine();
                }
                catch (Exception)
                {
                }

                int count = 1;
                foreach (var park in parks)
                {
                    Console.WriteLine((count + ") ").ToString().PadLeft(7) + park.Name);
                    count++;
                }
                // View My Reservations
                Console.WriteLine("R)".PadLeft(6) + " View all my reservations");
                Console.WriteLine("Q)".PadLeft(6) + " Quit");
                Console.WriteLine();

                string input = CLIHelper.GetString("Please select a park: ");
                if (input.Equals("Q") || input.Equals("q"))
                {
                    exit = true;
                }

                else if (input.Equals("R") || input.Equals("r"))
                {
                    ShowAllUserReservations();
                }

                else
                {
                    if (int.TryParse(input, out int selection))
                    {
                        if (selection > 0 || selection <= parks.Count)
                        {
                            _selectedPark = parks[selection - 1];
                            ParkInfoMenu();
                        }
                    }
                    else
                    {
                        DisplayInvalidOption();
                    }
                }
            }
        }
 public void Cleanup()
 {
     _park = null;
     _tran.Dispose();
 }
        /// <summary>
        /// Displays a list of campgrounds and prompts user to select one of them
        /// </summary>
        /// <param name="park">The park the campgrounds belong to</param>
        /// <param name="campgrounds">List of campgrounds</param>
        private void DisplaySearchMenu(ParkItem park, List <CampgroundItem> campgrounds)
        {
            Dictionary <int, CampgroundItem> menu = new Dictionary <int, CampgroundItem>();
            decimal selectedDailyFee = 0.0M;
            string  campgroundName   = "";

            bool exit = false;

            while (!exit)
            {
                ReservationInfo reservation = new ReservationInfo();

                bool validSelection = false;
                while (!validSelection)
                {
                    menu.Clear();
                    Console.Clear();
                    DisplayColored("Search for Campground Reservation");
                    Console.WriteLine();
                    DisplayCampgrounds(campgrounds, menu);
                    Console.WriteLine();

                    var selection = CLIHelper.GetInteger("Which campground (enter 0 to cancel)?");
                    if (selection == 0)
                    {
                        exit           = true;
                        validSelection = true;
                    }
                    else if (menu.ContainsKey(selection))
                    {
                        reservation.CampgroundId = menu[selection].Id;
                        selectedDailyFee         = menu[selection].DailyFee;
                        campgroundName           = menu[selection].Name;
                        validSelection           = true;
                    }
                    else
                    {
                        DisplayInvalidSelection();
                    }
                }

                if (!exit)
                {
                    try
                    {
                        reservation = GetReservationInfo(reservation);
                    }
                    catch (ExitException)
                    {
                        exit = true;
                    }

                    try
                    {
                        DisplayCampsiteSelection(reservation, selectedDailyFee, campgroundName);
                        throw new ExitToMainException();
                    }
                    catch (NoAvailableCampsitesException)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There are no campsites available that match your search criteria.");
                        Console.WriteLine(Message_PressKeyContinue);
                        Console.ReadKey();
                    }
                    catch (ExitException)
                    {
                        exit = true;
                    }
                    catch (ExitToMainException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        CLIHelper.DisplayDebugInfo(e);
                    }
                }
            }
        }