public async Task <IActionResult> Create([Bind("ID,VehicleName,Type,CurrentFuelLevel,NumberOfTires")] Vehicle vehicle) { if (ModelState.IsValid) { _context.Add(vehicle); // Add tires Tire[] tires = new Tire[vehicle.NumberOfTires]; for (int i = 0; i < vehicle.NumberOfTires; i++) { tires[i] = new Tire(); tires[i].VehicleID = vehicle.ID; _context.Add(tires[i]); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicle)); }
public async Task <IActionResult> Create([Bind("ID")] Tire tire) { if (ModelState.IsValid) { _context.Add(tire); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tire)); }