Beispiel #1
0
        public async Task <IActionResult> AddUser()
        {
            PasswordEmployeeViewModel emp = new PasswordEmployeeViewModel();

            ViewBag.Departments = await _webApiCalls.GetDepartmentsForDropDown();

            ViewBag.Roles = await _webApiCalls.GetRolesForDropdown();

            ViewBag.Rooms = await _webApiCalls.GetRoomsForDropdown();

            return(View(emp));
        }
Beispiel #2
0
        public async Task <IActionResult> ChangePassword(string employeeId)
        {
            var user = await _userManager.FindByIdAsync(employeeId);

            if (user == null)
            {
                return(RedirectToAction("UserManagement", _userManager.Users));
            }

            var model = new PasswordEmployeeViewModel()
            {
                Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Active = user.Active
            };

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> AddUser(PasswordEmployeeViewModel emp)
        {
            if (!ModelState.IsValid || emp.Password != emp.ConfirmPassword)
            {
                return(View(emp));
            }

            var e = new Employee()
            {
                UserName     = emp.Email,
                Email        = emp.Email,
                FirstName    = emp.FirstName,
                LastName     = emp.LastName,
                DepartmentId = emp.DepartmentId,
                RoomId       = emp.RoomId
            };

            IdentityResult result = await _userManager.CreateAsync(e, emp.Password);

            if (result.Succeeded)
            {
                var role = await _roleManager.FindByIdAsync(emp.RoleId);

                IdentityResult roleResult = await _userManager.AddToRoleAsync(e, role.Name);

                return(RedirectToAction("UserManagement", _userManager.Users));
            }

            foreach (IdentityError error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }

            ViewBag.Departments = await _webApiCalls.GetDepartmentsForDropDown();

            ViewBag.Roles = await _webApiCalls.GetRolesForDropdown();

            ViewBag.Rooms = await _webApiCalls.GetRoomsForDropdown();

            return(View(emp));
        }
Beispiel #4
0
        public async Task <IActionResult> ChangePassword(string employeeId, PasswordEmployeeViewModel model)
        {
            if (!ModelState.IsValid && model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "Passwords Must Match");
                return(View(model));
            }

            var user = await _userManager.FindByIdAsync(model.Id);

            await _userManager.RemovePasswordAsync(user);

            var change = await _userManager.AddPasswordAsync(user, model.ConfirmPassword);

            if (!change.Succeeded)
            {
                return(View(model));
            }

            return(RedirectToAction("UserManagement"));
        }