public static void Configure() { string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent. Parent.Parent.FullName; Kernel = new StandardKernel(); int loggerChoice = ConsoleIO.PromptInt("What kind of logging do you want?" + "\n1. None\n2. Console\n3. File\n", 1, 3); switch (loggerChoice) { case 2: Kernel.Bind <ILogger>().To <ConsoleLogger>(); break; case 3: Kernel.Bind <ILogger>().To <FileLogger>().WithConstructorArgument("_filePath", "log.txt"); break; default: Kernel.Bind <ILogger>().To <NullLogger>(); break; } Kernel.Bind <IReservationRepository>().To <ReservationFileRepository>() .WithConstructorArgument("directory", projectDirectory + "\\reservations"); Kernel.Bind <IGuestRepository>().To <GuestFileRepository>() .WithConstructorArgument("file", Path.Combine(projectDirectory, "guests.csv")); Kernel.Bind <IHostRepository>().To <HostFileRepository>() .WithConstructorArgument("file", Path.Combine(projectDirectory, "hosts.csv")); }
private void Cancel() { ConsoleIO.DisplayLine("*** Cancel Reservation ***"); //get host list and reservations //when getting list to show, query to only show future dates Result <List <Reservation> > reservationsResult = GetReservations(); List <Reservation> orderedReservations = reservationsResult.Value .Where(r => r.StartDate > DateTime.Now) .ToList(); ConsoleIO.DisplayStatus(reservationsResult.Success, reservationsResult.Messages); if (reservationsResult.Success) { ConsoleIO.DisplayReservationList(orderedReservations); } else { return; } //get id to delete Reservation toDelete = null; do { int idToDelete = ConsoleIO.PromptInt("Enter the ID of the Reservation you want to cancel"); toDelete = reservationsResult.Value.Find(r => r.ID == idToDelete); } while (toDelete == null); //confirm deletion ConsoleIO.DisplayLine($"\nCancelling reservation {toDelete.ID}"); if (!ConsoleIO.PromptYesNo()) { ConsoleIO.DisplayLine("Reservation was not deleted"); return; } //perform Delete and show result var result = reservationService.Delete(toDelete); ConsoleIO.DisplayStatus(result.Success, result.Messages); if (result.Success) { ConsoleIO.DisplayLine($"Reservation with ID {result.Value.ID} was deleted"); } }
public void Run() { do { ConsoleIO.DisplayLine("Main Menu\n======="); int menuChoice = ConsoleIO.PromptInt("0. Exit\n1. View Reservations\n2. Add a Reservation" + "\n3. Update a Reservation\n4. Cancel a Reservation" + "\nEnter choice [0-4]", 0, 4); switch (menuChoice) { case 1: View(); ConsoleIO.AnyKeyToContinue(); break; case 2: Add(); ConsoleIO.AnyKeyToContinue(); break; case 3: Update(); ConsoleIO.AnyKeyToContinue(); break; case 4: Cancel(); ConsoleIO.AnyKeyToContinue(); break; default: ConsoleIO.DisplayLine("You chose to exit"); if (ConsoleIO.PromptYesNo()) { ConsoleIO.DisplayLine("Goodbye!"); return; } else { break; } } } while (true); }
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"); } }