Esempio n. 1
0
        public static List <PostFacebookDAO> BuscarTodosPosts()
        {
            var query  = "SELECT * FROM post";
            var cmd    = new MySqlCommand(query, Conexao.Connection);
            var reader = cmd.ExecuteReader();
            List <PostFacebookDAO> list = new List <PostFacebookDAO>();

            while (reader.Read())
            {
                var data = reader["data"].ToString();
                var post = new PostFacebookDAO
                {
                    Id       = int.Parse(reader["id_post"].ToString()),
                    IdPagina = int.Parse(reader["id_pagina"].ToString()),
                    IdCidade = int.Parse(reader["id_cidade"].ToString()),
                    id       = reader["id_redesocial"].ToString(),
                    link     = reader["link"].ToString(),
                    Data     = DateTime.ParseExact(data, "dd/MM/yyyy HH:mm:ss", null),
                    message  = reader["titulo"].ToString(),
                };
                list.Add(post);
            }
            Conexao.Connection.Close();
            return(list);
        }
Esempio n. 2
0
        public static List <PostFacebookDAO> BuscarPostsPagina(long idPagina, int ultimosDias = 0)
        {
            Conexao.Connection.Close();
            var query = $"SELECT * FROM post WHERE id_pagina = {idPagina}";

            if (ultimosDias > 0)
            {
                query += $" and data > now() - interval {ultimosDias} day";
            }
            var cmd    = new MySqlCommand(query, Conexao.Connection);
            var reader = cmd.ExecuteReader();
            List <PostFacebookDAO> list = new List <PostFacebookDAO>();

            while (reader.Read())
            {
                var data = reader["data"].ToString();
                var post = new PostFacebookDAO
                {
                    Id       = int.Parse(reader["id_post"].ToString()),
                    IdPagina = int.Parse(reader["id_pagina"].ToString()),
                    IdCidade = int.Parse(reader["id_cidade"].ToString()),
                    id       = reader["id_redesocial"].ToString(),
                    link     = reader["link"].ToString(),
                    Data     = DateTime.ParseExact(data, "dd/MM/yyyy HH:mm:ss", null),
                    message  = reader["titulo"].ToString(),
                };
                list.Add(post);
            }
            Conexao.Connection.Close();
            return(list);
        }