Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Get the connection string from the appsettings.json file
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            string connectionString = configuration.GetConnectionString("npcampground");

            IParksDAO       parksDAO       = new ParksSqlDAO(connectionString);
            ICampgroundDAO  campgroundDAO  = new CampgroundSqlDAO(connectionString);
            ISiteDAO        siteDAO        = new SiteSqlDAO(connectionString);
            IReservationDAO reservationDAO = new ReservationSqlDAO(connectionString);

            MainCLI       mainCLI       = new MainCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
            ParkCLI       parkCLI       = new ParkCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
            CampGroundCLI campGroundCLI = new CampGroundCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
            SiteCLI       siteCLI       = new SiteCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);

            mainCLI.RunMainMenuCLI();
        }
        /// <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;
                            }
                        }
                    }
                }
            }
        }