예제 #1
0
        public ArticuloModel GetInfoPaginaResumen(int id)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            ArticuloModel articulo = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand cmd = new SqlCommand("SELECT * FROM Articulo WHERE Articulo.idArticuloPK = @id", connection);
                cmd.Parameters.AddWithValue("@id", id);

                SqlDataReader identReader = cmd.ExecuteReader();

                while (identReader.Read())
                {
                    articulo = new ArticuloModel((string)identReader["titulo"], (string)identReader["resumen"], (int)identReader["tipo"],
                                                 (string)identReader["contenido"],
                                                 identReader["fechaPublicacion"].ToString().Remove(identReader["fechaPublicacion"].ToString().Length - 12, 12),
                                                 (string)identReader["nombreAutor"], (string)identReader["usernameFK"]);
                }

                identReader.Close();
            }
            return(articulo);
        }
예제 #2
0
        public List <ArticuloModel> GetTodosArticulos()
        {
            String connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand cmd = new SqlCommand("SELECT  idArticuloPK, titulo, resumen, tipo, contenido, fechaPublicacion, nombreAutor, usernameFK " +
                                                " FROM  Articulo ORDER BY fechaPublicacion DESC", connection);

                SqlDataReader identReader = cmd.ExecuteReader();

                List <ArticuloModel> art = new List <ArticuloModel>();
                while (identReader.Read())
                {
                    ArticuloModel am = new ArticuloModel((int)identReader.GetValue(0),
                                                         (String)identReader.GetValue(1), (String)identReader.GetValue(2),
                                                         (int)identReader.GetValue(3), (String)identReader.GetValue(4),
                                                         identReader.GetValue(5).ToString().Remove(identReader.GetValue(5).ToString().Length - 12, 12),
                                                         (String)identReader.GetValue(6), (String)identReader.GetValue(7));
                    art.Add(am);
                }

                identReader.Close();

                return(art);
            }
        }
예제 #3
0
        public List <ArticuloModel> GetArticlesByAutorEdit(String autor)
        {
            String connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand cmd;

                cmd = new SqlCommand("SELECT  DISTINCT Articulo.idArticuloPK, Articulo.titulo, Articulo.resumen, Articulo.tipo, Articulo.contenido, Articulo.fechaPublicacion, Articulo.nombreAutor, Articulo.usernameFK " +
                                     " FROM  Articulo  WHERE usernameFK LIKE @autor ORDER BY Articulo.titulo ", connection);
                cmd.Parameters.AddWithValue("@autor", autor);
                SqlDataReader identReader = cmd.ExecuteReader();

                List <ArticuloModel> art = new List <ArticuloModel>();
                while (identReader.Read())
                {
                    ArticuloModel am = new ArticuloModel((int)identReader.GetValue(0),
                                                         (String)identReader.GetValue(1), (String)identReader.GetValue(2),
                                                         (int)identReader.GetValue(3), (String)identReader.GetValue(4),
                                                         identReader.GetValue(5).ToString().Remove(identReader.GetValue(5).ToString().Length - 12, 12),
                                                         (String)identReader.GetValue(6), (String)identReader.GetValue(7));
                    art.Add(am);
                }

                identReader.Close();

                return(art);
            }
        }
예제 #4
0
        public void  SaveArticulo(ArticuloModel articulo, List <TopicoModel> topicos)
        {
            String connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                String sqlString = "INSERT INTO Articulo(titulo, resumen, tipo, contenido, fechaPublicacion, nombreAutor, usernameFK)";
                sqlString += "VALUES(@titulo, @resumen, @tipo, @contenido, @fechaPublicacion, @nombreAutor, @usernameFK)";

                using (SqlCommand command = new SqlCommand(sqlString, connection))
                {
                    command.Parameters.AddWithValue("@titulo", articulo.titulo);
                    command.Parameters.AddWithValue("@resumen", articulo.resumen);
                    command.Parameters.AddWithValue("@tipo", articulo.tipo);
                    command.Parameters.AddWithValue("@contenido", articulo.contenido);
                    command.Parameters.AddWithValue("@fechaPublicacion", articulo.fechaPublicacion);
                    command.Parameters.AddWithValue("@nombreAutor", articulo.nombreAutor);
                    command.Parameters.AddWithValue("@usernameFK", articulo.usernameFK);

                    connection.Open();
                    command.ExecuteNonQuery();

                    articulo.idArticuloPK = ObtenerSiguienteId();
                    command.CommandText   = "INSERT INTO TopicosArticulo VALUES(@idArticuloFK, @nombreTopicoFK)";

                    foreach (TopicoModel topico in topicos)
                    {
                        command.Parameters.Clear();
                        command.Parameters.AddWithValue("@idArticuloFK", articulo.idArticuloPK);
                        command.Parameters.AddWithValue("@nombreTopicoFK", topico.nombre);
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
예제 #5
0
        public List <ArticuloModel> GetArticulosPorTopico(String topico, int tipos)
        {
            String connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand cmd;

                switch (tipos)
                {
                case 1:
                    cmd = new SqlCommand("SELECT  DISTINCT Articulo.idArticuloPK, Articulo.titulo, Articulo.resumen, Articulo.tipo, Articulo.contenido, Articulo.fechaPublicacion, Articulo.nombreAutor, Articulo.usernameFK " +
                                         " FROM  Articulo JOIN TopicosArticulo ON " +
                                         " Articulo.idArticuloPK = TopicosArticulo.idArticuloFK JOIN Topico ON " +
                                         " TopicosArticulo.nombreTopicoFK = @topico AND Articulo.tipo = 0 ORDER BY fechaPublicacion DESC", connection);
                    break;

                case 2:
                    cmd = new SqlCommand("SELECT  DISTINCT Articulo.idArticuloPK, Articulo.titulo, Articulo.resumen, Articulo.tipo, Articulo.contenido, Articulo.fechaPublicacion, Articulo.nombreAutor, Articulo.usernameFK " +
                                         " FROM  Articulo JOIN TopicosArticulo ON " +
                                         " Articulo.idArticuloPK = TopicosArticulo.idArticuloFK JOIN Topico ON " +
                                         " TopicosArticulo.nombreTopicoFK = @topico AND Articulo.tipo = 1 ORDER BY fechaPublicacion DESC", connection);
                    break;

                default:
                    cmd = new SqlCommand("SELECT  DISTINCT Articulo.idArticuloPK, Articulo.titulo, Articulo.resumen, Articulo.tipo, Articulo.contenido, Articulo.fechaPublicacion, Articulo.nombreAutor, Articulo.usernameFK " +
                                         " FROM  Articulo JOIN TopicosArticulo ON " +
                                         " Articulo.idArticuloPK = TopicosArticulo.idArticuloFK JOIN Topico ON " +
                                         " TopicosArticulo.nombreTopicoFK = @topico ORDER BY fechaPublicacion DESC", connection);
                    break;
                }


                cmd.Parameters.AddWithValue("@topico", topico);

                SqlDataReader identReader = cmd.ExecuteReader();

                List <ArticuloModel> art = new List <ArticuloModel>();
                while (identReader.Read())
                {
                    ArticuloModel am = new ArticuloModel((int)identReader.GetValue(0),
                                                         (String)identReader.GetValue(1), (String)identReader.GetValue(2),
                                                         (int)identReader.GetValue(3), (String)identReader.GetValue(4),
                                                         identReader.GetValue(5).ToString().Remove(identReader.GetValue(5).ToString().Length - 12, 12),
                                                         (String)identReader.GetValue(6), (String)identReader.GetValue(7));
                    art.Add(am);
                }

                identReader.Close();

                return(art);
            }
        }
예제 #6
0
        public List <ArticuloModel> GetArticulosPorTitulo(String titulo, int tipos)
        {
            String connectionString = ConfigurationManager.ConnectionStrings["Grupo4Conn"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand cmd;

                switch (tipos)
                {
                case 1:
                    cmd = new SqlCommand("SELECT  idArticuloPK, titulo, resumen, tipo, contenido, fechaPublicacion, nombreAutor, usernameFK " +
                                         " FROM  Articulo  WHERE titulo LIKE @titulo AND tipo = 0 ORDER BY fechaPublicacion DESC", connection);
                    break;

                case 2:
                    cmd = new SqlCommand("SELECT  idArticuloPK, titulo, resumen, tipo, contenido, fechaPublicacion, nombreAutor, usernameFK " +
                                         " FROM  Articulo  WHERE titulo LIKE @titulo AND tipo = 1 ORDER BY fechaPublicacion DESC", connection);
                    break;

                default:
                    cmd = new SqlCommand("SELECT  idArticuloPK, titulo, resumen, tipo, contenido, fechaPublicacion, nombreAutor, usernameFK " +
                                         " FROM  Articulo  WHERE titulo LIKE @titulo ORDER BY fechaPublicacion DESC", connection);
                    break;
                }

                cmd.Parameters.AddWithValue("@titulo", "%" + titulo + "%");

                SqlDataReader identReader = cmd.ExecuteReader();

                List <ArticuloModel> art = new List <ArticuloModel>();
                while (identReader.Read())
                {
                    ArticuloModel am = new ArticuloModel((int)identReader.GetValue(0),
                                                         (String)identReader.GetValue(1), (String)identReader.GetValue(2),
                                                         (int)identReader.GetValue(3), (String)identReader.GetValue(4),
                                                         identReader.GetValue(5).ToString().Remove(identReader.GetValue(5).ToString().Length - 12, 12),
                                                         (String)identReader.GetValue(6), (String)identReader.GetValue(7));
                    art.Add(am);
                }

                identReader.Close();

                return(art);
            }
        }