Пример #1
0
        public async Task <IActionResult> Edit(string userId, List <string> roles)
        {
            var account = _userManagerService.FindByIdRole(userId);

            if (account != null)
            {
                // получем список ролей пользователя
                var userRoles = await _userManagerService.GetRolesByAccount(userId);

                // получаем все роли
                var allRoles = _userManagerService.ShowListOfRoles();
                // получаем список ролей, которые были добавлены
                var addedRoles = roles.Except(userRoles);
                // получаем роли, которые были удалены
                var removedRoles = userRoles.Except(roles);

                await _userManagerService.AddToRole(userId, addedRoles);

                await _userManagerService.RemovedFromRoles(userId, removedRoles);

                return(RedirectToAction("UserList"));
            }

            return(NotFound());
        }