public async Task <IActionResult> Edit(string id, [Bind("ID,Make,Price,DriverID")] Car car) { if (id != car.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException /* ex */) { if (!CarExists(car.ID)) { return(NotFound()); } else { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } return(RedirectToAction(nameof(Index))); } ViewData["DriverID"] = new SelectList(_context.Drivers, "ID", "FirstName", car.DriverID); return(View(car)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,LastName,FirstName,License")] Driver driver) { if (id != driver.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(driver); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DriverExists(driver.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(driver)); }
public async Task <IActionResult> Edit(string id, [Bind("ID,Make,Price,DriverID")] Car car) { if (id != car.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DriverID"] = new SelectList(_context.Drivers, "ID", "FirstName", car.DriverID); return(View(car)); }