public ActionResult <VehicleModel> AddVehicleToRace(int raceId, VehicleCreateDto vehicle) { VehicleSubtypeModel subtypeModel = _dakarRepo.GetVehicleSubtype(vehicle.VehicleType, vehicle.VehicleSubtype); if (subtypeModel == null) { return(BadRequest("Invalid vehicle type and/or subtype.")); } VehicleModel vehicleToCreate = _mapper.Map <VehicleModel>(vehicle); vehicleToCreate.VehicleSubtype = subtypeModel; if (_dakarRepo.AddVehicleToRace(raceId, vehicleToCreate, out string status)) { _dakarRepo.SaveChanges(); return(Ok(vehicleToCreate)); } return(BadRequest(status)); }
public ActionResult <VehicleModel> UpdateVehicle(VehicleUpdateDto vehicle) { VehicleModel vehicleToUpdate = _dakarRepo.UpdateVehicle(vehicle.Id, out string status); if (vehicleToUpdate == null) { return(BadRequest(status)); } VehicleSubtypeModel subtypeModel = _dakarRepo.GetVehicleSubtype(vehicle.VehicleType, vehicle.VehicleSubtype); if (subtypeModel == null) { return(BadRequest("Invalid vehicle type and/or subtype.")); } _mapper.Map(vehicle, vehicleToUpdate); vehicleToUpdate.VehicleSubtype = subtypeModel; _dakarRepo.SaveChanges(); return(Ok(vehicleToUpdate)); }