public async Task <IActionResult> Edit(int id, [Bind("Id,First,Last,Month,Year,EmployeeTypeID")] Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EmployeeTypeID"] = new SelectList(_context.EmployeeType, "EmployeeTypeID", "EmployeeTypeID", employee.EmployeeTypeID); return(View(employee)); }
public async Task <IActionResult> Edit(int id, [Bind("DeptId,DeptName")] Department department) { if (id != department.DeptId) { return(NotFound()); } if (ModelState.IsValid) { try { using (var context = new EmployeeManagementContext()) { context.Update(department); await context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.DeptId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //return View(author); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int?id, [Bind("ID,FirstName,LastName,Gender,Birth,Department,Address,Phone,Email")] Employee employee) { if (id != employee.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } } return(View(employee)); }
public async Task <IActionResult> Edit(int id, [Bind("EmpId,Name,Surname,Address,Qualification,ContactNumber,DeptId")] Employee employee) { if (id != employee.EmpId) { return(NotFound()); } if (ModelState.IsValid) { try { using (var _context = new EmployeeManagementContext()) { _context.Update(employee); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.EmpId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } using (var _context = new EmployeeManagementContext()) { ViewData["DeptId"] = new SelectList(_context.Departments, "DeptId", "DeptId", employee.DeptId); } return(View(employee)); }