Exemplo n.º 1
0
        internal EmployeeWithDepartmentAndRoomAndRole Map(Employee e, Department d, Room r, IdentityRole ir)
        {
            var employee = new EmployeeWithDepartmentAndRoomAndRole
            {
                Active    = e.Active,
                Email     = e.Email,
                FirstName = e.FirstName,
                Id        = e.Id,
                LastName  = e.LastName
            };

            if (d != null)
            {
                employee.DepartmentId   = d?.Id;
                employee.DepartmentName = d?.DepartmentName;
            }

            if (r != null)
            {
                employee.RoomId   = r.Id;
                employee.RoomName = r.RoomName;
            }

            if (ir != null)
            {
                employee.RoleId   = ir?.Id;
                employee.RoleName = ir?.Name;
            }

            return(employee);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditUser(EmployeeWithDepartmentAndRoomAndRole emp)
        {
            var user = await _userManager.FindByIdAsync(emp.Id);

            if (user != null)
            {
                user.FirstName    = emp.FirstName;
                user.LastName     = emp.LastName;
                user.DepartmentId = emp.DepartmentId;
                user.RoomId       = emp.RoomId;
                user.Active       = emp.Active;
                user.Email        = emp.Email;
            }

            var result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(RedirectToAction("UserManagement", _userManager.Users));
            }

            ModelState.AddModelError("", "User not updated, something went wrong.");

            ViewBag.Departments = await _webApiCalls.GetDepartmentsForDropDown();

            ViewBag.Roles = await _webApiCalls.GetRolesForDropdown();

            ViewBag.Rooms = await _webApiCalls.GetRoomsForDropdown();

            return(View(emp));
        }