public void CreateReservationTest()
        {
            string reservationName = "Test reservation";

            DateTime fromDate = new DateTime(1900, 01, 20);

            DateTime toDate = new DateTime(1900, 01, 21);

            DateTime currentDate = DateTime.Now;

            int reservationId = _db.AddReservation(1, reservationName, fromDate, toDate);

            Reservation reservation = _db.GetReservation(reservationId);

            Assert.AreEqual(reservationName, reservation.Name);
            Assert.AreEqual(fromDate.Date, reservation.FromDate.Date);
            Assert.AreEqual(toDate.Date, reservation.ToDate.Date);
            Assert.AreEqual(currentDate.Date, reservation.CreateDate.Date);
        }
Exemplo n.º 2
0
        private void SearchForCampgroundReservation(int parkId, Dictionary <int, Campground> campgrounds)
        {
            bool quit = false;

            while (!quit)
            {
                Console.Clear();
                DisplayCampgroundsByPark(parkId, campgrounds);

                try
                {
                    //Need to add verification
                    Console.WriteLine("\nWhich campground (enter 0 to cancel)?");
                    string userCampgroundChoiceString = Console.ReadLine();
                    int    userCampgroundChoice       = int.Parse(userCampgroundChoiceString);

                    Console.WriteLine("What is the arrival date? (MM/DD/YYYY)");
                    string   arrivalDateString = Console.ReadLine();
                    DateTime arrivalDate       = Convert.ToDateTime(arrivalDateString);

                    Console.WriteLine("What is the departure date? (MM/DD/YYYY)");
                    string   departureDateString = Console.ReadLine();
                    DateTime departureDate       = Convert.ToDateTime(departureDateString);

                    if (arrivalDate > departureDate)
                    {
                        throw new Exception();
                    }

                    if (userCampgroundChoice == 0)
                    {
                        quit = true;
                    }
                    else
                    {
                        Dictionary <int, Site> sites = _db.FindAvailableSites(userCampgroundChoice, arrivalDate, departureDate);

                        if (sites.Count == 0)
                        {
                            Console.Clear();
                            Console.WriteLine("No sites are avaible for the given dates");
                            Console.WriteLine("Press any key to return to the previous screen...");
                            Console.ReadKey();
                            break;
                        }

                        Console.WriteLine("Results Matching Your Search Criteria");
                        Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(12) + "Max RV Length".PadRight(15) + "Utility".PadRight(10) + "Cost");

                        foreach (var site in sites)
                        {
                            decimal costOfReservation = campgrounds[site.Value.CampgroundId].DailyFee *
                                                        (decimal)(departureDate - arrivalDate).TotalDays;

                            Console.WriteLine($"{site.Value.SiteNum}".PadRight(10) + $"{site.Value.SiteOccupancy}".PadRight(12) +
                                              $"{site.Value.DisplayAccessible}".PadRight(12) + $"{site.Value.DisplayMaxRVLength}".PadRight(15) +
                                              $"{site.Value.DisplayUtilities}".PadRight(10) + costOfReservation.ToString("C"));
                        }
                        Console.WriteLine("Which site should be reserved (enter 0 to cancel)?");
                        string userChoice = Console.ReadLine();


                        try
                        {
                            int siteNum = int.Parse(userChoice);

                            if (sites.ContainsKey(siteNum))
                            {
                                Console.WriteLine("What name should the reservation be made under?");
                                string reservationName   = Console.ReadLine();
                                int    reservationNumber = _db.AddReservation(sites[siteNum].Id, reservationName, arrivalDate, departureDate);
                                Console.WriteLine($"\nThe reservation has been made and the confirmation id is {reservationNumber}");
                                Console.WriteLine($"\nPress any key to return to the campgrounds screen...");
                                Console.ReadKey();
                                quit = true;
                            }
                            else if (siteNum == 0)
                            {
                                quit = true;
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                        catch
                        {
                            Console.Clear();
                            Console.WriteLine("Please enter only valid command");
                            Console.Write("Press any key to return to the campgrounds screen...");
                            Console.ReadKey();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Something went wrong!");
                    Console.ReadKey();
                }
            }
        }
Exemplo n.º 3
0
        private void CreateReservation(int userCampgroundChoice, Dictionary <int, Campground> campgrounds)
        {
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine("What is the arrival date? (MM/DD/YYYY)");
                string   arrivalDateString = Console.ReadLine();
                DateTime arrivalDate       = parseDateFromString(arrivalDateString);

                Console.WriteLine("What is the departure date? (MM/DD/YYYY)");
                string   departureDateString = Console.ReadLine();
                DateTime departureDate       = parseDateFromString(departureDateString);
                try
                {
                    Dictionary <int, Site> sites = new Dictionary <int, Site>();
                    if (arrivalDate >= DateTime.Now.Date && arrivalDate < departureDate)
                    {
                        sites = _db.FindAvailableSites(userCampgroundChoice, arrivalDate, departureDate);
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("The arrival and/or departure dates are invalid.");
                        Console.WriteLine("Would you like to enter a new set of dates? (Y) for yes or (N) for no");
                        string reenterDateChoice = Console.ReadLine();

                        if (reenterDateChoice.ToLower() == "y")
                        {
                            break;
                        }
                        else if (reenterDateChoice.ToLower() == "n")
                        {
                            quit = true;
                            break;
                        }
                        else
                        {
                            throw new InvalidYesNoException("Your input was invalid. Please enter (Y) for yes or (N) for no");
                        }
                    }


                    if (sites.Count == 0)
                    {
                        Console.Clear();
                        Console.WriteLine("No sites are available for the given dates");
                        Console.WriteLine("Would you like to enter a new set of dates? (Y) for yes or (N) for no");
                        string reenterDateChoice = Console.ReadLine();

                        if (reenterDateChoice.ToLower() == "y")
                        {
                            break;
                        }
                        else if (reenterDateChoice.ToLower() == "n")
                        {
                            quit = true;
                            break;
                        }
                        else
                        {
                            throw new InvalidYesNoException("Your input was invalid. Please enter (Y) for yes or (N) for no");
                        }
                    }


                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(12) + "Max RV Length".PadRight(15) + "Utility".PadRight(10) + "Cost");


                    foreach (var site in sites)
                    {
                        decimal costOfReservation = campgrounds[site.Value.CampgroundId].DailyFee *
                                                    (decimal)(departureDate - arrivalDate).TotalDays;

                        Console.WriteLine($"{site.Value.SiteNum}".PadRight(10) + $"{site.Value.SiteOccupancy}".PadRight(12) +
                                          $"{site.Value.DisplayAccessible}".PadRight(12) + $"{site.Value.DisplayMaxRVLength}".PadRight(15) +
                                          $"{site.Value.DisplayUtilities}".PadRight(10) + costOfReservation.ToString("C"));
                    }
                    Console.WriteLine("Which site should be reserved (enter 0 to cancel)?");

                    string userChoice = Console.ReadLine();
                    int    siteNum    = parseUserChoiceFromString(userChoice);

                    if (sites.ContainsKey(siteNum))
                    {
                        Console.WriteLine("What name should the reservation be made under?");
                        string reservationName   = Console.ReadLine();
                        int    reservationNumber = _db.AddReservation(sites[siteNum].Id, reservationName, arrivalDate, departureDate);
                        Console.WriteLine($"\nThe reservation has been made.\nThe confirmation id is {reservationNumber}");
                        Console.WriteLine($"\nPress any key to return to the campgrounds screen...");
                        Console.ReadKey();
                        quit = true;
                    }
                    else if (siteNum == 0)
                    {
                        quit = true;
                    }
                    else
                    {
                        throw new OnlyValidChoiceException("Please enter only valid site.");
                    }
                }
                catch (Exception ex)
                {
                    Console.Clear();
                    Console.WriteLine(ex.Message);
                    Console.Write("Press any key to return to the campgrounds screen...");
                    quit = true;
                    Console.ReadKey();
                }
            }
        }