public ActionResult PopUpRoles(RolesViewModel vm, params string[] rolesSelectedOnView)
 {
     UpdateUserRoles(vm, rolesSelectedOnView);
     return null;
 }
        private void UpdateUserRoles(RolesViewModel vm, string[] rolesSelectedOnView)
        {
            if (!ModelState.IsValid) return;

            var user = _userManager.FindById(vm.UserId);
            if (user == null)
                return;
            var rolesCurrentlyPersistedForUser = _userManager.GetRoles(user.Id);

            if (rolesSelectedOnView != null)
            {
                var netRolesToAdd = rolesSelectedOnView.Except(rolesCurrentlyPersistedForUser);
                //Add Selected Roles that were not previously persisted in db
                foreach (var role in netRolesToAdd)
                {
                    _userManager.AddToRoles(user.Id, role);
                }
            }

            //Remove Unselected Roles that were previoiusly persisted in db
            if (rolesCurrentlyPersistedForUser != null)
            {
                var netRolesToRemove = rolesCurrentlyPersistedForUser.Except(rolesSelectedOnView).ToArray();

                foreach (var t in netRolesToRemove)
                {
                    _userManager.RemoveFromRole(user.Id, t);
                }
            }
        }
        public ActionResult PopUpRoles(string id)
        {
            var user = _userManager.FindById(id);
            if (user == null)
                return View();
            var rolesCurrentlyPersistedForUser = _userManager.GetRoles(user.Id);

            //var rolesCurrentlyPersistedForUser = Roles.GetRolesForUser(user.UserName);

            var userRoles = GenerateRolesList(rolesCurrentlyPersistedForUser);

            ViewBag.Id = id;
            var viewModel = new RolesViewModel
            {
                RolesList = userRoles,
                UserId = id,
                FLName = user.UserName
            };
            return View(viewModel);
        }