Ejemplo n.º 1
0
        /// <summary>
        /// Main Menu that prints header and menu options. Pressing one will open the Park Reservation service and Q will quit application
        /// </summary>
        public void RunMainMenuCLI()
        {
            PrintHeader();
            PrintMainMenu();

            while (true)
            {
                string userChoice = Console.ReadLine();

                Console.Clear();

                switch (userChoice.ToLower())
                {
                case "1":

                    ParkCLI parkCLI = new ParkCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
                    parkCLI.RunParkCLI();

                    break;

                case "q":
                    PrintHeader();
                    Console.WriteLine();
                    Console.WriteLine("---------------------------------------------------------THANK YOU FOR USING THE NATIONAL PARK RESERVATION SERVICE--------------------------------------------------------", Color.GreenYellow);
                    Console.WriteLine("__________________________________________________________________________________________________________________________________________________________________________", Color.DimGray);
                    Console.WriteLine("**************************************************************      Press [ENTER] to exit the service      ***************************************************************", Color.LightSteelBlue);
                    Console.ReadLine();
                    Environment.Exit(0);
                    return;

                default:
                    Console.WriteLine("The command provided was not a valid command, please try again.");
                    break;
                }
            }
        }
        /// <summary>
        /// Runs menu to give user a choice of campgrounds from the choosen park.
        /// </summary>
        /// <param name="parkName"></param>
        /// <param name="parkId"></param>
        public void RunCampGroundCLI(string parkName, int parkId)
        {
            List <string> Wrap(string text, int margin)
            {
                int start = 0, end;
                var lines = new List <string>();

                text = Regex.Replace(text, @"\s", " ").Trim();

                while ((end = start + margin) < text.Length)
                {
                    while (text[end] != ' ' && end > start)
                    {
                        end -= 1;
                    }

                    if (end == start)
                    {
                        end = start + margin;
                    }

                    lines.Add(text.Substring(start, end - start));
                    start = end + 1;
                }

                if (start < text.Length)
                {
                    lines.Add(text.Substring(start));
                }

                return(lines);
            }

            IList <Park> parks = parksDAO.GetAllParks();

            foreach (Park park in parks)
            {
                List <string> decript = Wrap(park.Description, 155);
                foreach (string dp in decript)
                {
                    Console.WriteLine($"         {dp}");
                }
                Console.WriteLine();

                userParkId = parkId;
                IList <Park> pa = parksDAO.GetAllParks();
                parkName = "";
                string parkDecript = "";
                foreach (Park name in pa)
                {
                    if (name.ParkId == userParkId)
                    {
                        parkName    = name.Name;
                        parkDecript = name.Description;
                    }
                }
                Console.Clear();
                PrintHeader();
                Console.WriteLine();
                Console.WriteLine($"                                                                         {parkName}", Color.Yellow);
                Console.WriteLine("__________________________________________________________________________________________________________________________________________________________________________", Color.DimGray);
                Console.WriteLine();
                foreach (string dp in decript)
                {
                    Console.WriteLine($"         {dp}", Color.DarkKhaki);
                }
                Console.WriteLine();
                Console.WriteLine("__________________________________________________________________________________________________________________________________________________________________________", Color.DimGray);

                GetCampGroundList();
                PrintCampGroundChoices();

                while (true)
                {
                    string             userChoice  = Console.ReadLine();
                    IList <Campground> campgrounds = campgroundDAO.Search(userParkId);
                    foreach (Campground campground in campgrounds)
                    {
                        string cgIdString = campground.CampgroundId.ToString();
                        if (userChoice == cgIdString)
                        {
                            Console.WriteLine();
                            DateTime fromDate = CLIHelper.GetDateTime("Please Enter Arrival Date(YYYY-MM-DD): ");
                            DateTime toDate   = CLIHelper.GetDateTime("Please Enter Departure Date (YYYY-MM-DD): ");
                            SiteCLI  siteCLI  = new SiteCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
                            siteCLI.RunSiteCLI(parkName, parkId, campground.CampgroundId, campground.Name, campground.DailyFee, fromDate, toDate);
                        }
                        else
                        {
                            switch (userChoice.ToLower())
                            {
                            case "p":
                                Console.Clear();
                                ParkCLI parkCLI = new ParkCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
                                parkCLI.RunParkCLI();
                                break;

                            default:
                                Console.WriteLine("The command provided was not a valid command, please try again.", Color.Red);
                                break;
                            }
                        }
                    }
                }
            }
        }