public async Task <IActionResult> UpdateUser(CompleteEmployeeView cEmployee, string id) //id = employeeId { string employeeId = id; Employee employeeToSave = new Employee { DepartmentId = cEmployee.DepartmentId, RoleTitle = cEmployee.RoleTitle, EmployeeId = employeeId, EmployeeName = cEmployee.EmployeeName }; string dbEmployeeRoleString = (await repository.GetEmployee(employeeId)).RoleTitle; if (!cEmployee.RoleTitle.Equals(dbEmployeeRoleString)) //changed role { IdentityUser updatedUser = await userManager.FindByNameAsync(employeeId); await userManager.AddToRoleAsync(updatedUser, cEmployee.RoleTitle); if (dbEmployeeRoleString != null) { if (await userManager.IsInRoleAsync(updatedUser, dbEmployeeRoleString)) { await userManager.RemoveFromRoleAsync(updatedUser, dbEmployeeRoleString); //Remove from previous role if emp was in one. } } } repository.UpdateEmployee(employeeToSave); return(RedirectToAction("EmployeeModification", new { id = employeeId })); }
/// <summary> /// Opens the view where you can enter data to change role, department, and name of an employee /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ViewResult> EmployeeModification(string id) //id = employeeId { CompleteEmployeeView employee = await repository.GetCompleteViewOfEmployee(id); ViewBag.EmployeeID = id; ViewBag.Roles = GetRoles(); ViewBag.Departments = repository.Departments; return(View(employee)); }