public ActionResult EditUser(AdminUserViewModel AdminModel)
        {
            var user = db.Users.Find(AdminModel.User.Id);

            foreach (var rolermv in db.Roles.Select(r => r.Name).ToList())
            {
                userManager.RemoveUserFromRole(user.Id, rolermv);
            }

            foreach (var roleadd in AdminModel.SelectedRoles)
            {
                userManager.AddUserToRole(user.Id, roleadd);
            }
            return(RedirectToAction("Index"));
        }
示例#2
0
        public ActionResult SelectRole(UserRoleViewModel model)
        {
            var user = db.Users.Find(model.Id);

            foreach (var roler in db.Roles.Select(r => r.Id).ToList())
            // foreach (var rolermv in user.Roles.ToList())
            {
                helper.RemoveUserFromRole(user.Id, roler);
            }

            foreach (var roleadd in model.SeletedRoles)
            {
                helper.AddUserToRole(user.Id, roleadd);
            }
            ViewBag.Confirm = "User's role had been successfully modified";
            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult SelectRole(UserRoleViewModel model)
        {
            var user = db.Users.Find(model.Id);

            foreach (var roleName in db.Roles.Select(r => r.Name).ToList())
            {
                userRole.RemoveUserFromRole(user.Id, roleName);
            }
            if (model.SelectedRoles != null)
            {
                foreach (var roleadd in model.SelectedRoles)
                {
                    userRole.AddUserToRole(user.Id, roleadd);
                }
            }
            return(RedirectToAction("Index"));
        }
示例#4
0
        public ActionResult SelectRole(UserRoleViewModel model)
        {
            var user = db.Users.Find(model.Id);

            foreach (var rolemv in db.Roles.Select(r => r.Name).ToList())
            {
                helper.RemoveUserFromRole(user.Id, rolemv);
            }
            if (model.SelectedRoles != null)
            {
                foreach (var rolemv in model.SelectedRoles)
                {
                    helper.AddUserToRole(user.Id, rolemv);
                }
            }
            ViewBag.confim = "User's role has been sucessfully modified";
            return(RedirectToAction("Index"));
        }