public List <Accion> ListarAcciones() { using (SqlConnection connection = new SqlConnection(connectionSQL)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; transaction = connection.BeginTransaction("Listar acciones"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = $"SELECT * FROM acciones"; transaction.Commit(); using (SqlDataReader response = command.ExecuteReader()) { if (response.HasRows) { var acciones = new List <Modelo.Accion>(); while (response.Read()) { var accion = new Modelo.Accion() { ID = response.GetInt32(0), Descripcion = response.GetString(1) }; acciones.Add(accion); } return(acciones); } } } catch (Exception ex2) { throw ex2; } } throw new Exception("Ha ocurrido un error"); }
public List <Accion> ListarAccionesDisponibles(int idUser, int idVista) { using (SqlConnection connection = new SqlConnection(connectionSQL)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; transaction = connection.BeginTransaction("Listar vistas disponibles"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = $"SELECT DISTINCT acciones.id, acciones.tipo, acciones.icon_name FROM permisos INNER JOIN acciones on permisos.accion_id = acciones.id WHERE permisos.grupo_id IN (SELECT grupo_id FROM usuarios_grupos INNER JOIN grupos ON grupos.id = usuarios_grupos.grupo_id WHERE usuario_id = {idUser} AND grupos.estado = 1) AND vista_id = {idVista} AND tiene_permiso = 1"; transaction.Commit(); using (SqlDataReader response = command.ExecuteReader()) { if (response.HasRows) { var acciones = new List <Modelo.Accion>(); while (response.Read()) { var accion = new Modelo.Accion(); accion.ID = response.GetInt32(0); accion.Descripcion = response.GetString(1); accion.IconName = response.GetString(2); acciones.Add(accion); } return(acciones); } } throw new Exception("No se han podido encontrar acciones disponibles"); } catch (Exception ex) { throw ex; } } throw new Exception("Ha ocurrido un error"); }