Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }