Пример #1
0
        private void Add()
        {
            ConsoleIO.DisplayLine("*** Add Reservation ***");

            //get the host list and resrvations
            Result <List <Reservation> > reservationsResult = GetReservations();

            ConsoleIO.DisplayStatus(reservationsResult.Success, reservationsResult.Messages);

            if (reservationsResult.Success)
            {
                ConsoleIO.DisplayReservationList(reservationsResult.Value);
            }
            else
            {
                return;
            }

            //instantiate a host
            Host host = reservationsResult.Value.FirstOrDefault().Host;

            //get guest & instantiate
            string         guestEmail  = ConsoleIO.PromptString("Enter guest email", false);
            Result <Guest> guestResult = reservationService.FindGuestByEmail(guestEmail);


            if (!guestResult.Success)
            {
                ConsoleIO.DisplayStatus(guestResult.Success, guestResult.Messages);
                return;
            }
            else
            {
                ConsoleIO.DisplayLine("Guest found");
                ConsoleIO.DisplayLine("");
            }
            Guest guest = guestResult.Value;

            //get start date (required)
            DateTime startDate = ConsoleIO.PromptDateTime("Reservation start date", false);
            //get end date (required)
            DateTime endDate = ConsoleIO.PromptDateTime("Reservation end date", false);

            //perform Create and display result
            Reservation toAdd = new Reservation
            {
                StartDate = startDate,
                EndDate   = endDate,
                Guest     = guest,
                Host      = host
            };

            toAdd.SetTotal();

            ConsoleIO.DisplayReservationSummary(toAdd);
            if (!ConsoleIO.PromptYesNo())
            {
                ConsoleIO.DisplayLine("Reservation was not added");
                return;
            }

            Result <Reservation> createResult = reservationService.Create(toAdd);

            ConsoleIO.DisplayStatus(createResult.Success, createResult.Messages);

            if (createResult.Success)
            {
                ConsoleIO.DisplayLine($"Reservation with ID {createResult.Value.ID} created");
            }
        }
Пример #2
0
        private void Update()
        {
            ConsoleIO.DisplayLine("*** Update Reservation ***");

            //get host list and reservations
            Result <List <Reservation> > reservationsResult = GetReservations();

            ConsoleIO.DisplayStatus(reservationsResult.Success, reservationsResult.Messages);

            if (reservationsResult.Success)
            {
                ConsoleIO.DisplayReservationList(reservationsResult.Value);
            }
            else
            {
                return;
            }

            //get id to edit
            Reservation original = null;

            do
            {
                int idToEdit = ConsoleIO.PromptInt("Enter the ID of the Reservation you want to edit");
                original = reservationsResult.Value.Find(r => r.ID == idToEdit);
            } while (original == null);

            ConsoleIO.DisplayLine($"\n** Editing Reservation {original.ID} **");

            //prompt new start date (or enter to keep)
            DateTime newStart = ConsoleIO.PromptDateTime($"New start ({original.StartDate:d})", true);
            //prompt new end date (or enter to keep)
            DateTime newEnd = ConsoleIO.PromptDateTime($"New end ({original.EndDate:d})", true);

            //instantiate a host
            Host host = original.Host;

            //set up Reservation, show summary and confirm correct
            Reservation toUpdate = new Reservation
            {
                Host  = host,
                Guest = original.Guest
            };

            toUpdate.StartDate = newStart == default(DateTime) ? original.StartDate :  newStart; //if PromptDateTime returned the default,
                                                                                                 //we know user wants it the same.
            toUpdate.EndDate = newEnd == default(DateTime) ? original.EndDate : newEnd;
            toUpdate.SetTotal();

            ConsoleIO.DisplayReservationSummary(toUpdate);
            if (!ConsoleIO.PromptYesNo())
            {
                ConsoleIO.DisplayLine("Reservation was not updated");
                return;
            }

            //perform Update and display result
            toUpdate.ID = original.ID;
            var result = reservationService.Update(original.ID, toUpdate);

            ConsoleIO.DisplayStatus(result.Success, result.Messages);
            if (result.Success)
            {
                ConsoleIO.DisplayLine($"Reservation with ID {result.Value.ID} was updated");
            }
        }