static Reservation GetReservation() { Console.WriteLine("Please enter a reservationID"); var reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); using (var db = new RentCDb()) { while (!db.Reservations.Any(r => r.ReservationID == reservationID)) { Console.WriteLine("Please enter a valid reservationID"); reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); } var reservation = db.Reservations.Find(reservationID); ReservationManagement.DisplayReservationInfo(reservation); return(reservation); } }
public static void DisplayScreen() { Reservation reservation = new Reservation(); Console.Write("Car Plate:"); var carPlate = Console.ReadLine(); var carID = ReservationManagement.ValidateCar(carPlate); reservation.CarID = carID; Console.Write("Client ID:"); var clientID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); reservation.CostumerID = ReservationManagement.ValidateClient(clientID); Console.Write("Start Date(mm.dd.yyyy):"); var startDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); Console.Write("End Date(mm.dd.yyyy):"); var endDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); reservation.StartDate = ReservationManagement.ValidateDates(startDate, endDate).Item1; reservation.EndDate = ReservationManagement.ValidateDates(startDate, endDate).Item2; Console.Write("Location:"); var location = Console.ReadLine(); reservation.LocationID = ReservationManagement.ValidateCarLocation(carID, location); List <Nullable <DateTime> > carReserved = ReservationManagement.IsCarAvailabe(carID, startDate, endDate); if (carReserved.Count() > 0) { Console.WriteLine("Car is not available on: " + carReserved); ReservationManagement.DisplayReservationInfo(reservation); } using (var db = new RentCDb()) { Car car = db.Cars.Find(reservation.CarID); var price = car.PricePerDay * (decimal)((endDate - startDate).TotalDays); decimal totalPrice; Console.WriteLine("The car is available for " + car.PricePerDay + "/day"); Console.Write("Do you have a cupone code?\nIf yes enter it, if no type NO: "); var ans = Console.ReadLine(); if (ans.ToUpper() == "NO") { totalPrice = price; } else { var customerCupon = Console.ReadLine(); var cupon = db.Coupons.FirstOrDefault(c => c.CouponCode == customerCupon); if (cupon != null) { Console.WriteLine("Discount: " + cupon.Discount + ": " + cupon.Description); totalPrice = price - (cupon.Discount * price); } totalPrice = price; } Console.WriteLine("Total price: " + totalPrice); Console.WriteLine("Save the reservation? Type YES to save \nNO to go back to main menu: "); ans = Console.ReadLine(); if (ans == "NO") { MenuPage.SelectOption(); } else { reservation.ReservStatsID = 1; db.Reservations.Add(reservation); db.SaveChanges(); } } }
public static void UpdateRental() { // Reservation reservation = GetReservation(); Console.WriteLine("Please enter a reservationID"); var reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); using (var db = new RentCDb()) { while (!db.Reservations.Any(r => r.ReservationID == reservationID)) { Console.WriteLine("Please enter a valid reservationID"); reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); } var reservation = db.Reservations.Find(reservationID); ReservationManagement.DisplayReservationInfo(reservation); Options: var ans = UpdateCarRentalOptions(); switch (ans) { case "1": Console.WriteLine("Please enter a new car Plate"); var carPlate = Console.ReadLine(); var carID = ReservationManagement.ValidateCar(carPlate); reservation.CarID = carID; db.SaveChanges(); break; case "2": Console.WriteLine("Please enter a Client ID:"); var clientID = ReservationManagement.ValidateClient (ValidateUserInput.ValidateInputInt(Console.ReadLine())); reservation.CostumerID = clientID; db.SaveChanges(); break; case "3": Console.WriteLine("Please enter Start Date (mm.dd.yyy):"); var enteredStartDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); var validStartDate = ReservationManagement.ValidateDates(enteredStartDate, reservation.EndDate).Item1; reservation.StartDate = validStartDate; db.SaveChanges(); break; case "4": Console.WriteLine("Please enter End Date (mm.dd.yyy):"); var enteredEndDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); var validEndDate = ReservationManagement.ValidateDates(reservation.StartDate, enteredEndDate).Item2; reservation.EndDate = validEndDate; db.SaveChanges(); break; case "5": Console.WriteLine("Please enter a new location: "); var enteredLocation = Console.ReadLine(); var newLocation = ReservationManagement.ValidateCarLocation(reservation.CarID, enteredLocation); reservation.LocationID = newLocation; db.SaveChanges(); break; default: Console.WriteLine("Option not available"); goto Options; } Console.WriteLine("New Reservation Data:"); ReservationManagement.DisplayReservationInfo(reservation); Console.WriteLine("Would you like to modify something else? \n" + "If yes, type YES if no type NO to go back to main menu"); ans = Console.ReadLine(); if (ans.ToUpper() == "NO") { MenuPage.SelectOption(); } else if (ans.ToUpper() == "YES") { goto Options; } db.SaveChanges(); } }