示例#1
0
        public static List<string> getCategorias()
        {
            MySQL mysql = new MySQL();
            List<string> categorias = new List<string>();
            IList<IDictionary<string, string>> selectCategorias = mysql.selectQuery("select nome from categorias");
            foreach (Dictionary<string, string> categoria in selectCategorias)
            {
                categorias.Add(categoria["nome"]);
            }

            return categorias;
        }
示例#2
0
 public static List<Comentario> getAllCommentariosAprovados(int idPost)
 {
     List<Comentario> comentarios = new List<Comentario>();
     MySQL mysql = new MySQL();
     string selectComments = "select comentarios.id, usuarios.nome_exibicao, comentarios.conteudo, comentarios.status from comentarios";
     selectComments += " left join usuarios on comentarios.id_usuario = usuarios.id";
     selectComments += " where comentarios.status='aprovado' AND comentarios.id_post = " + idPost;
     IList<IDictionary<string, string>> query = mysql.selectQuery(selectComments);
     foreach (Dictionary<string, string> row in query)
     {
         comentarios.Add(new Comentario{
             id=int.Parse(row["id"]),
             nomeExibicaoUsuario=row["nome_exibicao"],
             conteudo=row["conteudo"],
             status=row["status"]
         });
     }
     return comentarios;
 }
示例#3
0
 public static Post getPost(int id)
 {
     MySQL mysql = new MySQL();
     string selectPost = "select posts.id,usuarios.nome_exibicao,posts.data,posts.titulo,posts.conteudo from posts left join usuarios on posts.id_usuario = usuarios.id where posts.id=" + id;
     IList<IDictionary<string, string>> query = mysql.selectQuery(selectPost);
     List<string> categoriasDoPost = getCategoriasPost(int.Parse(query[0]["id"]));
     int idPost = int.Parse(query[0]["id"]);
     Post post = new Post
     {
         id = idPost,
         usuario = query[0]["nome_exibicao"],
         data = DateTime.Parse(query[0]["data"]),
         titulo = query[0]["titulo"],
         conteudo = query[0]["conteudo"],
         categorias = categoriasDoPost,
         comentarios = getAllCommentariosAprovados(idPost)
     };
     return post;
 }