public ActionResult DeleteAccount(string UserName) { try { if (!WebSecurity.UserExists(UserName)) { return(Content(String.Format("<h4 class='text-danger'>Не найден пользователь '{0}'</h4>", UserName))); } string[] userRoles = Roles.GetRolesForUser(UserName); if (userRoles.Count() > 0) { Roles.RemoveUserFromRoles(UserName, userRoles); } SimpleMembershipProvider provider = Membership.Provider as SimpleMembershipProvider; bool deleteResult = provider.DeleteAccount(UserName); deleteResult = deleteResult && provider.DeleteUser(UserName, true); if (deleteResult) { return(Content(String.Format("<h4 class='text-success'>Аккаунт пользователя '{0}' успешно удален</h4>", UserName))); } else { return(Content(String.Format("<h4 class='text-danger'>Аккаунта пользователя '{0}' возможно не удалось удалить полностью</h4>", UserName))); } } catch (Exception) { return(Content(String.Format("<h4 class='text-danger'>Возникли ошибки в процессе удаления аккаунта пользователя '{0}'</h4>", UserName))); } }
public JsonResult Delete(Guid id) { try { Customer customer = unitOfWork.CustomerRepository().GetByID(id); int userId = customer.UserId; unitOfWork.CustomerRepository().Delete(customer); unitOfWork.Save(); SimpleMembershipProvider membership = (SimpleMembershipProvider)Membership.Provider; string userName = membership.GetUserNameFromId(userId); if (Roles.GetRolesForUser(userName).Count() > 0) { Roles.RemoveUserFromRoles(userName, Roles.GetRolesForUser(userName)); } membership.DeleteAccount(userName); membership.DeleteUser(userName, true); return(this.Json(new { success = true })); } catch { return(this.Json(new { success = false })); } }
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")); } }
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 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); } }