protected void AddOutImageButton_Click(object sender, EventArgs e) { string[] ListOfUsersToDeleteFromRol; ListOfUsersToDeleteFromRol = GetUserIDs(InRoleListBox); if (ListOfUsersToDeleteFromRol == null) { SystemMessages.DisplaySystemMessage(Resources.SecurityData.MessageUsersNoSelected); return; } string userType = "Normal"; bool CanDeleteCurrentUserFromRole = true; CanDeleteCurrentUserFromRole = SecurityBLL.CanDeleteUserFromRole(ListOfUsersToDeleteFromRol, HttpContext.Current.User.Identity.Name, RoleDropDownList.SelectedValue, ref userType); if (CanDeleteCurrentUserFromRole) { if (ListOfUsersToDeleteFromRol != null && ListOfUsersToDeleteFromRol.Length > 0) { Roles.RemoveUsersFromRole(ListOfUsersToDeleteFromRol, RoleDropDownList.Text); foreach (String UserDeleted in ListOfUsersToDeleteFromRol) { try { UserBLL.DeleteUserInRoles(UserDeleted, RoleDropDownList.Text); log.Debug("El Usuario " + UserDeleted + " ha sido eliminado del Rol " + RoleDropDownList.Text + "."); SystemMessages.DisplaySystemMessage(string.Format(Resources.SecurityData.MessageDeletedRoleUser, UserDeleted, RoleDropDownList.Text)); } catch { SystemMessages.DisplaySystemErrorMessage(string.Format(Resources.SecurityData.MessageErrorDeleteRoleUser, UserDeleted, RoleDropDownList.Text)); } } } else { SystemMessages.DisplaySystemMessage(Resources.SecurityData.MessageNoUsersInList); } } else { if (userType == "Normal") { log.Error("No se puede eliminar el Usuario " + HttpContext.Current.User.Identity.Name + " del rol " + RoleDropDownList.SelectedValue + " porque es el útimo con privilegios administrativos"); SystemMessages.DisplaySystemWarningMessage(string.Format(Resources.SecurityData.MessageWarningDeleteAdministrativeUser, HttpContext.Current.User.Identity.Name, RoleDropDownList.SelectedValue)); } else if (userType == "Admin") { log.Error("No se puede eliminar el Usuario " + ConfigurationManager.AppSettings.Get("AdminUser") + " del Rol " + RoleDropDownList.SelectedValue + " porque es el útimo grupo con privilegios de administración y es el Administrador del Sistema"); SystemMessages.DisplaySystemWarningMessage(string.Format(Resources.SecurityData.MessageWarningDeleteAdminUser, ConfigurationManager.AppSettings.Get("AdminUser"), RoleDropDownList.SelectedValue)); } } BindData(); }
protected void AddInImageButton_Click(object sender, EventArgs e) { string[] ListOfUsersToAddToRol; ListOfUsersToAddToRol = GetUserIDs(OutRoleListBox); if (ListOfUsersToAddToRol != null && ListOfUsersToAddToRol.Length > 0) { if (RoleDropDownList.Text == Resources.SecurityData.NoneRoleItem) { foreach (String UserAdded in ListOfUsersToAddToRol) { string[] AllRoles = Roles.GetAllRoles(); foreach (String Rol in AllRoles) { if (Roles.IsUserInRole(UserAdded, Rol)) { bool CanDeleteCurrentUserFromRole = true; string userType = "Normal"; CanDeleteCurrentUserFromRole = SecurityBLL.CanDeleteUserFromRole(ListOfUsersToAddToRol, HttpContext.Current.User.Identity.Name, Rol, ref userType); if (CanDeleteCurrentUserFromRole) { Roles.RemoveUserFromRole(UserAdded, Rol); UserBLL.DeleteUserInRoles(UserAdded, Rol); } else { log.Error("No se puede eliminar el Usuario " + HttpContext.Current.User.Identity.Name + " del rol " + RoleDropDownList.SelectedValue + " porque es el útimo con privilegios administrativos"); SystemMessages.DisplaySystemMessage(string.Format(Resources.SecurityData.MessageWarningDeleteAdministrativeUser, HttpContext.Current.User.Identity.Name, RoleDropDownList.SelectedValue)); } } } } } else { Roles.AddUsersToRole(ListOfUsersToAddToRol, RoleDropDownList.Text); foreach (String UserAdded in ListOfUsersToAddToRol) { UserBLL.InsertUserInRoles(UserAdded, RoleDropDownList.Text); log.Debug("El Usuario " + UserAdded + " ha sido adicionado al Rol " + RoleDropDownList.Text + "."); SystemMessages.DisplaySystemMessage(string.Format(Resources.SecurityData.MessageUserRegisteredInRole, UserAdded, RoleDropDownList.Text)); } } } else { SystemMessages.DisplaySystemMessage(Resources.SecurityData.MessageUsersNoSelected); } BindData(); }