public ActionResult RoleAddUser(string id, string selectedUserNameFromList)
        {
            SimpleRoleProvider simpleRoles = Roles.Provider as SimpleRoleProvider;

            if (!simpleRoles.IsUserInRole(selectedUserNameFromList, id))
            {
                simpleRoles.AddUsersToRoles(new string[] { selectedUserNameFromList }, new string[] { id });
            }
            return(PartialView("RoleUserList", simpleRoles.GetUsersInRole(id)));
        }
        public ActionResult RoleEdit(string id)
        {
            SimpleRoleProvider simpleRoles = Roles.Provider as SimpleRoleProvider;
            var model = new RoleModel(id)
            {
                PrevName = id,
                UserList = simpleRoles.GetUsersInRole(id)
            };

            return(View(model));
        }
        public ActionResult RoleEdit(RoleModel model)
        {
            SimpleRoleProvider simpleRoles = Roles.Provider as SimpleRoleProvider;
            var users = simpleRoles.GetUsersInRole(model.PrevName);

            simpleRoles.RemoveUsersFromRoles(users, new string[] { model.PrevName });
            simpleRoles.DeleteRole(model.PrevName, false);
            simpleRoles.CreateRole(model.Name);
            simpleRoles.AddUsersToRoles(users, new string[] { model.Name });

            return(RedirectToAction("RoleList"));
        }
        public ActionResult RoleDetails(string id)
        {
            SimpleRoleProvider simpleRoles = Roles.Provider as SimpleRoleProvider;
            var model = new RoleModel(id);

            model.UserList = simpleRoles.GetUsersInRole(id);
            using (var context = new UsersContext())
            {
                model.FullUserList = new SelectList(context.UserProfiles.ToList(), "UserName", "UserName");
            }

            return(View(model));
        }
Example #5
0
        /// <summary>
        /// Gets all users.
        /// </summary>
        /// <returns></returns>
        public override MembershipUserCollection GetAllUsers()
        {
            var allRoles  = this._roleProvider.GetAllRoles();
            var usernames = new List <string>();

            foreach (var role in allRoles)
            {
                usernames.AddRange(_roleProvider.GetUsersInRole(role));
            }

            var users = new MembershipUserCollection();

            foreach (var username in usernames)
            {
                var user = this._provider.GetUser(username, false);
                if (user != null)
                {
                    users.Add(user);
                }
            }

            return(users);
        }
        public ActionResult RoleUserList(string id)
        {
            SimpleRoleProvider simpleRoles = Roles.Provider as SimpleRoleProvider;

            return(PartialView(simpleRoles.GetUsersInRole(id)));
        }