Ejemplo n.º 1
0
        /// <summary>
        /// Select from available sites in selected campground
        /// </summary>
        /// <param name="campground"></param>
        /// <param name="arrival"></param>
        /// <param name="departure"></param>
        private void SiteSelectionMenu(Campground campground, DateTime arrival, DateTime departure)
        {
            Reservation reserve = new Reservation();

            reserve.FromDate = arrival;
            reserve.ToDate   = departure;
            bool quit = false;

            while (!quit)
            {
                SiteSqlDAL  siteSqlDAL = new SiteSqlDAL(_connectionString);
                List <Site> resList    = siteSqlDAL.GetAvailalableSitesInCampground(campground.CampgroundId, arrival, departure);
                TimeSpan    interval   = reserve.ToDate - reserve.FromDate;
                decimal     cost       = interval.Days * campground.DailyFee;

                if (resList.Count == 0)
                {
                    Console.WriteLine("\nNo sites available for the dates provided.");
                }
                else
                {
                    DisplayAvailableSites(resList, cost);

                    reserve.SiteId = 0;
                    int selection = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");
                    if (selection < 0)
                    {
                        Console.WriteLine(" Invalid selection. Please try again.");
                    }
                    //else if (selection == 0)
                    //{
                    //    quit = true;
                    //}
                    else if (selection > 0)
                    {
                        //var site = resList.Find(m => m.SiteId == selection);

                        for (int i = 0; i < resList.Count; i++)
                        {
                            if (resList[i].SiteNumber == selection)
                            {
                                reserve.SiteId = resList[i].SiteId;
                            }
                        }
                        if (reserve.SiteId == 0)
                        {
                            Console.WriteLine(" Invalid selection. Please try again.");
                        }
                    }
                    Console.WriteLine("What name Should the reservation be made under?");
                    reserve.Name = Console.ReadLine();
                    ReservationSqlDAL reservationSqlDAL = new ReservationSqlDAL(_connectionString);
                    reserve = reservationSqlDAL.AddReservation(reserve);
                    Console.WriteLine($"The reservation has been made and the confirmation id is {reserve.ReservationId}");

                    quit = true;
                }
            }
        }