public IActionResult Create(CreateBookingVM vm) { if (ModelState.IsValid) { TravelPackage package = _packageRepo.GetSingle(p => p.TravelPackageId == vm.PackageId); //get logged user info var userId = _userManager.GetUserId(User); double totalCost = vm.NumberOfPeople * package.Price; Booking booking = new Booking { DateBooked = DateTime.Now, StartDate = vm.StartDate, TotalPrice = totalCost, NumberOfPeople = vm.NumberOfPeople, PackageId = package.TravelPackageId, UserId = userId, PackageName = package.Name }; _bookingRepo.Create(booking); return(RedirectToAction("Index", "TravelPackage", new { id = booking.PackageId })); } return(View(vm)); }
internal void BookCar(CreateBookingVM createBooking) { Customer customer = new Customer(); if (carRentalContext.Customer.Any(c => c.CustomerSsn == createBooking.SSN)) { Customer existingCustomer = carRentalContext.Customer.Single(c => c.CustomerSsn == createBooking.SSN); customer = existingCustomer; } else { Customer newCustomer = new Customer { CustomerSsn = createBooking.SSN }; carRentalContext.Customer.Add(newCustomer); carRentalContext.SaveChanges(); customer = newCustomer; } Booking booking = new Booking { RentedCar = carRentalContext.Car.Single(c => c.CarRegistrationNumber == createBooking.RegistrationNumber).Id, CustomerId = customer.Id, }; carRentalContext.Car.SingleOrDefault(c => c.Id == booking.RentedCar).RentalStart = createBooking.StartOfRental; carRentalContext.Booking.Add(booking); carRentalContext.SaveChanges(); }
internal CreateBookingVM GetCarVM(string reg) { CreateBookingVM vm = new CreateBookingVM { //CarToBook = carRentalContext.Car.SingleOrDefault(c => c.CarRegistrationNumber == reg), }; return(vm); }
public IActionResult Book() { CreateBookingVM bookingVM = new CreateBookingVM { AvailableCars = service.GetAvailableCars() }; return(View(bookingVM)); }
public IActionResult Book(CreateBookingVM booking) { if (ModelState.IsValid) { service.BookCar(booking); return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public IActionResult Create(int id) { TravelPackage tp = _packageRepo.GetSingle(p => p.TravelPackageId == id); CreateBookingVM vm = new CreateBookingVM { TravelPackageName = tp.Name, PackageId = id, PackagePrice = tp.Price }; return(View(vm)); }
public IActionResult Book(string reg) { CreateBookingVM vm = service.GetCarVM(reg); return(View(vm)); }