public async Task <IActionResult> EditEmployee(EMPEditViewModel model) { var userUpdate = _context.EmployeeModel.First(m => m.EMPID == model.EmpID); // Things to Update userUpdate.EMP_FNAME = model.Employee_fname; userUpdate.EMP_LNAME = model.Employee_lname; userUpdate.UserName = model.Employee_userName; userUpdate.Email = model.Email; userUpdate.PhoneNumber = model.PhoneNumber; // UPDATE THE EMPLOYEE _context.EmployeeModel.Update(userUpdate); try { await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogCritical(e.ToString()); return(View()); } ViewData["Msg"] = "User Updated"; return(View(model)); }
public IActionResult EditEmployee(int?empId) { // If there isn't a vaule passed, then use the active user if (empId == null) { var uid = _userManager.GetUserId(User); empId = _context.EmployeeModel.First(E => E.Id == uid).EMPID; } var userContext = _context.EmployeeModel.First(m => m.EMPID == empId); var updateForm = new EMPEditViewModel { EmpID = userContext.EMPID, Employee_fname = userContext.EMP_FNAME, Employee_lname = userContext.EMP_LNAME, Employee_userName = userContext.UserName, Email = userContext.Email, PhoneNumber = userContext.PhoneNumber }; return(View(updateForm)); }