Exemple #1
0
        // Retorna lista com titulos das noticias nome do autor e id da noticia
        public List <NoticiaAutor> LeNoticias()
        {
            List <NoticiaAutor> listaNoticias = new List <NoticiaAutor>();

            try
            {
                // Lê noticias limitado a 500 registros
                var sql = "SELECT autores.Nome, noticias.Titulo, noticias.id_noticia FROM noticias left join autores on autores.id_autor = noticias.id_autor limit 500;";

                OdbcDataReader queryReader = _ctrlConexao.ExecQuery(sql);

                while (queryReader.Read())
                {
                    {
                        NoticiaAutor noticiaAutor = new NoticiaAutor()
                        {
                            autor      = queryReader.GetString(0),
                            titulo     = queryReader.GetString(1),
                            id_noticia = queryReader.GetString(2)
                        };
                        listaNoticias.Add(noticiaAutor);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(listaNoticias);
        }
Exemple #2
0
        // Retorna lista com titulos das noticias nome do autor e id da noticia que atendem o filtro da pesquisa
        public List <NoticiaAutor> PesquisaNoticias(string filtro)
        {
            List <NoticiaAutor> listaNoticias = new List <NoticiaAutor>();

            try
            {
                // Lê noticias que atendem o filtro
                var sql = "SELECT * FROM " +
                          "(SELECT autores.Nome, noticias.Titulo, noticias.Texto, noticias.id_noticia FROM noticias left join autores on autores.id_autor = noticias.id_autor " +
                          $") as a where Nome like '%{filtro}%' or Titulo like '%{filtro}%' or Texto like '%{filtro}%' order by Titulo, nome;";

                OdbcDataReader queryReader = _ctrlConexao.ExecQuery(sql);

                while (queryReader.Read())
                {
                    {
                        NoticiaAutor noticiaAutor = new NoticiaAutor()
                        {
                            autor      = queryReader.GetString(0),
                            titulo     = queryReader.GetString(1),
                            id_noticia = queryReader.GetString(3)
                        };
                        listaNoticias.Add(noticiaAutor);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(listaNoticias);
        }