public async Task <IActionResult> Edit(int id, [Bind("EmployeeId,FirstName,LastName,EmailAddress,PhoneNumber,DepartmentId")] EmployeeModel employeeModel) { if (id != employeeModel.EmployeeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employeeModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeModelExists(employeeModel.EmployeeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Department, "DepartmentId", "Name", employeeModel.DepartmentId); return(View(employeeModel)); }
public async Task <IActionResult> Edit(int id, [Bind("DepartmentId,Name")] DepartmentModel departmentModel) { if (id != departmentModel.DepartmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(departmentModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentModelExists(departmentModel.DepartmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(departmentModel)); }