Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("DriverID,UserID,Name,LicenseNumber")] Driver driver)
        {
            if (id != driver.DriverID)
            {
                return(NotFound());
            }

            if (!User.Identity.IsAuthenticated)
            {
                return(Challenge());
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, driver, "DriverInfoPolicy");

            if (!authResult.Succeeded)
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _driverRepository.EditAsync(driver);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_driverRepository.DriverExists(driver.DriverID))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(driver));
        }
Beispiel #2
0
 public bool DriverExists(int id)
 {
     return(_driverRepository.DriverExists(id));
 }