/// <summary> /// retorna um objeto ConteudoTexto com informações completas do Texto ou imagem ou video completos /// </summary> /// <param name="id">parametro inteiro do id ConteudoTexto</param> /// <returns></returns> public ConteudoTexto Consultar(int id) { SqlCommand comm = new SqlCommand("Select * from ConteudoTexto where ID_ConteudoTexto = " + id, Banco.Abrir()); SqlDataReader dr = comm.ExecuteReader(); ConteudoTexto c = new ConteudoTexto(); while (dr.Read()) { Texto t = null; if (dr.GetValue(2).ToString() != "") { t = new Texto(); TextoDAL daltex = new TextoDAL(); t = daltex.Consultar(Convert.ToInt32(dr.GetValue(2))); } Conteudo cc = new Conteudo { ID = Convert.ToInt32(dr.GetValue(1)) }; Imagem i = null; if (dr.GetValue(4).ToString() != "") { i = new Imagem(); ImagemDAL dalimg = new ImagemDAL(); i = dalimg.Consultar(Convert.ToInt32(dr.GetValue(4))); } Video v = null; if (dr.GetValue(3).ToString() != "") { v = new Video(); VideoDAL dalvid = new VideoDAL(); v = dalvid.Consultar(Convert.ToInt32(dr.GetValue(3))); } c = new ConteudoTexto { ID = Convert.ToInt32(dr.GetValue(0)), Conteudo = cc, Texto = t, Imagem = i, Video = v, Ordem = Convert.ToInt32(dr.GetValue(5)), Usuario = Convert.ToInt32(dr.GetValue(6)) }; } comm.Connection.Close(); return(c); }
/// <summary> /// Altera um Conteudo na tabela conteudo no Banco de dados /// Com Imagem Podendo ser nula /// </summary> /// <param name="C"> Parametro do tipo Conteudo| com id </param> public void Alterar(Conteudo C) { SqlCommand comm = new SqlCommand("", Banco.Abrir()); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "AlterarConteudo"; comm.Parameters.Add("@ID", SqlDbType.Int).Value = C.ID; comm.Parameters.Add("@Materia", SqlDbType.Int).Value = C.Materia.ID; comm.Parameters.Add("@Nome", SqlDbType.VarChar).Value = C.Nome; comm.Parameters.Add("@Ordem", SqlDbType.Int).Value = C.Ordem; comm.Parameters.Add("@Usuario", SqlDbType.Int).Value = C.Usuario; if (C.Imagem != null) { comm.Parameters.Add("@Imagem", SqlDbType.VarBinary).Value = C.Imagem; } comm.ExecuteNonQuery(); comm.Parameters.Clear(); comm.CommandType = CommandType.Text; try { comm.CommandText = "Delete From ConteudoTexto Where ID_Conteudo = " + C.ID; comm.ExecuteNonQuery(); } catch { } comm.CommandText = "Select Count(*) from Resumo Where ID_Conteudo = " + C.ID; if (Convert.ToInt32(comm.ExecuteScalar()) > 0) { comm.CommandText = "Delete From Resumo Where ID_Conteudo = " + C.ID; comm.ExecuteNonQuery(); } foreach (var item in C.ConteudoTexto) { if (item.Texto != null) { if (item.Texto.ID != 0) { TextoDAL dal = new TextoDAL(); dal.Deletar(item.Texto.ID); } } if (item.Imagem != null) { if (item.Imagem.ID != 0) { ImagemDAL dal = new ImagemDAL(); dal.Deletar(item.Imagem.ID); } } if (item.Video != null) { if (item.Video.ID != 0) { VideoDAL dal = new VideoDAL(); dal.Deletar(item.Video.ID); } } } comm.Connection.Close(); }