public ActionResult FirstStep(AnimalBookingVM animalBookingVM) { ModelState.Remove("Animals"); ModelState.Remove("UnavailableAnimals"); var tempBooking = (BookingVM)TempData["Booking"]; animalBookingVM.BookingDate = tempBooking.Booking.BookingDate; if (!ModelState.IsValid) { animalBookingVM.Animals = AnimalRepo.GetAnimals(); animalBookingVM.UnavailableAnimals = new List <Animal>(); foreach (var animal in animalBookingVM.Animals) { foreach (var booking in animal.Bookings) { if (booking.BookingDate == tempBooking.Booking.BookingDate) { animalBookingVM.UnavailableAnimals.Add(animal); } } } animalBookingVM.BookingDate = tempBooking.Booking.BookingDate; TempData["Booking"] = tempBooking; return(View(animalBookingVM)); } foreach (var animalId in animalBookingVM.AnimalIds) { tempBooking.Booking.Animals.Add(AnimalRepo.GetAnimal(animalId)); } TempData["Booking"] = tempBooking; return(RedirectToAction("SecondStep")); }
public ActionResult FirstStep() { var animalBookingVM = new AnimalBookingVM() { Animals = AnimalRepo.GetAnimals(), UnavailableAnimals = new List <Animal>() }; var bookingVM = (BookingVM)TempData["Booking"]; foreach (var animal in animalBookingVM.Animals) { foreach (var booking in animal.Bookings) { if (booking.BookingDate == bookingVM.Booking.BookingDate) { animalBookingVM.UnavailableAnimals.Add(animal); } } } animalBookingVM.BookingDate = bookingVM.Booking.BookingDate; TempData["Booking"] = bookingVM; return(View(animalBookingVM)); }