public List <Modelo.Vista> ListarVistas() { using (SqlConnection connection = new SqlConnection(connectionSQL)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; transaction = connection.BeginTransaction("Listar ID permisos"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = $"SELECT * FROM vistas"; transaction.Commit(); using (SqlDataReader response = command.ExecuteReader()) { if (response.HasRows) { var vistas = new List <Modelo.Vista>(); while (response.Read()) { var vista = new Modelo.Vista() { ID = response.GetInt32(0), Descripcion = response.GetString(1) }; vistas.Add(vista); } Conexion.Close(); return(vistas); } } } catch (Exception ex2) { throw ex2; } } throw new Exception("Ha ocurrido un error"); }
public List <Modelo.Vista> ListarVistasDisponibles(int id) { 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 vista_id, vistas.nombre FROM permisos INNER JOIN vistas ON permisos.vista_id = vistas.id WHERE grupo_id IN(SELECT grupo_id FROM usuarios_grupos INNER JOIN grupos ON grupos.id = usuarios_grupos.grupo_id WHERE usuario_id = {id} AND grupos.estado = 1) GROUP BY vista_id, nombre HAVING SUM(CAST(tiene_permiso AS INT)) > 0"; transaction.Commit(); using (SqlDataReader response = command.ExecuteReader()) { if (response.HasRows) { var vistas = new List <Modelo.Vista>(); while (response.Read()) { var vista = new Modelo.Vista(); vista.ID = response.GetInt32(0); vista.Descripcion = response.GetString(1); vistas.Add(vista); } return(vistas); } } throw new Exception("No se han podido encontrar vistas disponibles, contáctese con un administrador."); } catch (Exception ex) { throw ex; } } throw new Exception("Ha ocurrido un error"); }