public List <Libro> GetLibros(ParamBusquedaLibro param, bool incluirPublicos = true) { try { //var libros = (from l in _contexto.Libros // where // (l.Id_Usuario == StaticUserLogin.Id || l.IsPublico) // && (param.Id_Libro == 0 || (param.Id_Libro != 0 && l.Id == param.Id_Libro)) // && (param.Id_Estanteria == 0 || (param.Id_Estanteria != 0 && l.Id_Estanteria == param.Id_Estanteria)) // && (param.Id_Tipo_Estante == 0 || (param.Id_Tipo_Estante != 0 && l.Estanteria.Id_Tipo_Estante == param.Id_Tipo_Estante)) // && (param.TituloLibro == "" || (param.TituloLibro != "" && l.Titulo.ToUpper().Contains(param.TituloLibro.ToUpper()))) // select l).OrderBy(a => a.Titulo).ToList(); string query = string.Format("select l.Id " + "from Libros l " + "inner join Estanterias e on l.Id_Estanteria = e.Id " + "inner join Usuarios u on l.Id_Usuario = u.Id " + "left join Capitulos c on l.Id = c.Id_Libro " + "where " + "(l.Id_Usuario = {0} or l.IsPublico = 1) " + "and({1} = 0 or({1} <> 0 and l.Id = {1})) " + "and({2} = 0 or({2} <> 0 and l.Id_Estanteria = {2})) " + "and('{3}' = '' or('{3}' <> '' and l.Titulo like '%{3}%')) " + "and({4} = 0 or({4} <> 0 and c.Id = {4})) " + "and('{5}' = '' or('{5}' <> '' and c.Titulo like '%{5}%'))", StaticUserLogin.Id, param.Id_Libro, param.Id_Estanteria, param.TituloLibro, param.Id_Capitulo, param.TituloCapitulo); List <int> ids_Libros = _contexto.Database.SqlQuery <int>(query).ToList(); var libros = _contexto.Libros.Where(a => ids_Libros.Contains(a.Id)).ToList(); if (!incluirPublicos) { libros.RemoveAll(a => a.Id_Usuario != StaticUserLogin.Id && a.IsPublico); } return(libros); } catch (Exception ex) { StaticFileManager.LogError(ex); _errorMsg = "Ocurrio un error al realizar la busqueda"; return(null); } }
public List <Libro> GetLibroPrueba(ParamBusquedaLibro param, bool incluirPublicos = true) { var libros = _contexto.Database.SqlQuery <Libro>("").ToList(); return(libros); }