public ActionResult Edit(BookingDTO booking) { // if car type or hotel changed or check for tyre slots here UpdateBooking(booking); var line = FindAvailableSpace(booking); if (line == null) { ModelState.AddModelError(nameof(BookingDTO.GarageId), "No free service lines available in this garage at this time"); } else { booking.ServiceLineId = line.Value; } if (ModelState.IsValid) { var entity = bookingRepository.FindById(booking.Id); entity.ChangedAt = DateTime.Now; entity.Edited = true; bookingRepository.Update(BookingAssembler.Update(entity, booking)); return(RedirectToAction("Index")); } ViewBag.Garages = garageRepository.FindAllAsQueryable(i => !i.Deleted); return(View(booking)); }
public ActionResult Create(BookingDTO booking) { UpdateBooking(booking); var line = FindAvailableSpace(booking); if (line == null) { ModelState.AddModelError(nameof(BookingDTO.GarageId), "No free service lines available in this garage at this time"); } else { booking.ServiceLineId = line.Value; } int slots = !booking.TyreHotel ? 0 : booking.Type == Models.Enums.VehicleType.Car ? 1 : 2; var garage = garageRepository.FindById(booking.GarageId); if (garage.TyreSlots < slots) { ModelState.AddModelError(nameof(BookingDTO.TyreHotel), "Not enough free slots"); } else { garage.TyreSlots -= slots; garageRepository.Update(garage); } if (ModelState.IsValid) { bookingRepository.Insert(BookingAssembler.Create(booking)); return(RedirectToAction("Index")); } ViewBag.Garages = garageRepository.FindAllAsQueryable(); return(View(booking)); }