public IActionResult CreateBooking([FromBody] Booking booking) { int BookingId = _bookingRepo.Add(booking); var result = _bookingRepo.GetById(BookingId); return(CreatedAtAction(nameof(getById), new { id = BookingId }, result)); }
public IActionResult Create(Booking booking) { List <Car> allCars = _carRepo.AllCars(); foreach (var item in allCars) { if (item.LicensePlate == booking.Car.LicensePlate) { booking.Car = item; } } if (booking.Car.LicensePlate == null) { ViewBag.error = "Vänligen välj en bil, finns ingen måste du lägga till den först"; return(View()); } List <Customer> allCustomers = _customerRepo.AllCustomers(); foreach (var item in allCustomers) { if (item.SSN == booking.Customer.SSN) { booking.Customer = item; } } booking.Car.IsBooked = true; if (ModelState.IsValid) { ViewBag.ok = "Bokningen skapad"; _bookingRepo.Add(booking); return(View("~/Views/Home/Index.cshtml")); } ViewBag.error = "Något gick fel, vänligen försök igen"; return(View()); }