示例#1
0
        public ActionResult DeleteUser(int id = 0)
        {
            var user = userprofile.UserProfiles.ToList();
            SimpleRoleProvider       roles      = (SimpleRoleProvider)Roles.Provider;
            SimpleMembershipProvider membership = (SimpleMembershipProvider)Membership.Provider;

            UserProfile profile = userprofile.UserProfiles.Find(id);

            if (profile == null)
            {
                return(View(user));
            }
            else
            {
                var roole = roles.GetRolesForUser(profile.UserName);
                roles.RemoveUsersFromRoles(new[] { profile.UserName }, roole);
                membership.DeleteUser(profile.UserName, true);

                var autorised = Request.IsAuthenticated ? User.Identity.Name : "nothing";
                if (autorised == profile.UserName)
                {
                    WebSecurity.Logout();
                }

                TempData["_UserRole"] = "Prosto";
                return(RedirectToAction("DeleteUser"));
            }
        }
示例#2
0
        public void DeleteUser(string username)
        {
            var userRoles = roles.GetRolesForUser(username);

            foreach (var userRole in userRoles)
            {
                roles.RemoveUsersFromRoles(new[] { username }, new[] { userRole });
            }
            memberships.DeleteAccount(username);
            memberships.DeleteUser(username, true);
        }
        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"));
        }
示例#4
0
 public static void DeleteUserIfExist(string userName)
 {
     if (membership.GetUser(userName, false) != null)
     {
         if (roles.GetRolesForUser(userName).Count() > 0)
         {
             roles.RemoveUsersFromRoles(new[] { userName }, roles.GetRolesForUser(userName));
         }
         membership.DeleteAccount(userName);
         membership.DeleteUser(userName, true);
     }
 }
示例#5
0
 private void RemoveUserFromRoles(string userName)
 {
     string[] roles = rolesProvider.GetRolesForUser(userName);
     rolesProvider.RemoveUsersFromRoles(new[] { userName }, roles);
 }