public void AddCar(Car car) { int lastId = _dbContext.Cars.Max(c => c.CarID); car.CarID = lastId++; _dbContext.Cars.Add(car); _dbContext.SaveChanges(); }
public static void UpdateCustomer() { Console.Write("Please enter customerID :"); var customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); using (var db = new RentCDb()) { while (!db.Customers.Any(c => c.CostumerID == customerID)) { Console.WriteLine("Please enter an existing customer"); customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); } Customer customer = db.Customers.Find(customerID); DisplayCustomer(customer); Options: Console.WriteLine("Which field do you want to update?"); Console.WriteLine("1. Name"); Console.WriteLine("2. BirthDate"); var ans = Console.ReadLine(); switch (ans) { case "1": Console.Write("Enter Cusomer Name: "); customer.Name = Console.ReadLine(); break; case "2": Console.Write("Enter customer Birth Date: "); customer.BirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); break; default: Console.WriteLine("This is not a valid option!"); goto Options; } Console.WriteLine("New Reservation Data:"); DisplayCustomer(customer); 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 == "NO") { MenuPage.SelectOption(); } else if (ans == "YES") { goto Options; } db.SaveChanges(); Console.WriteLine("Customer saved:"); DisplayCustomer(customer); Console.ReadLine(); MenuPage.SelectOption(); } }
public static void AddCustomer() { Console.Write("Enter Cusomer Name: "); var customerName = Console.ReadLine(); Console.Write("Enter customer Birth Date: "); var customerBirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); Customer customer = new Customer { Name = customerName, BirthDate = customerBirthDate }; using (var db = new RentCDb()) { db.Customers.Add(customer); db.SaveChanges(); } Console.WriteLine("Customer saved:"); DisplayCustomer(customer); Console.ReadLine(); MenuPage.SelectOption(); }
public void Commit() { context.SaveChanges(); }
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(); } }
public void AddReservation(Reservation res) { _dbContext.Reservations.Add(res); _dbContext.SaveChanges(); }