public IActionResult Index(CarBoatModel carBoatModel) { //Check if the model if valid if (ModelState.IsValid) { //Check if the vehicle is a car or boat if (carBoatModel.mileage.HasValue) { //Create a car object Car car = new Car(carBoatModel.manufacturer, carBoatModel.model, carBoatModel.productYear.ToString(), carBoatModel.mileage.ToString()); //Inserts the car object DBL.InsertCar(car); } else { //Create a boat object Boat boat = new Boat(carBoatModel.manufacturer, carBoatModel.model, carBoatModel.productYear.ToString()); //Inserts the boat object DBL.InsertBoat(boat); } //Return the view return(View(new CarBoatModel())); } else { //Return the index view with the model return(View("Index", carBoatModel)); } }