public static List <Noticia> Listar(Noticia pNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_NOTICIA"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; if (pNoticia != null && pNoticia.TipoNoticia != null) { objComando.Parameters.Add("@TipoNoticiaId", SqlDbType.Int).Value = pNoticia.TipoNoticia.ID; } try { //Abre Conexao objConexao.Open(); //Declara variavel de retorno List <Noticia> objList = new List <Noticia>(); Noticia obj = default(Noticia); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { obj = new Noticia(); obj.FromIDataReader(idrReader); objList.Add(obj); } return(objList); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }
public static List <Noticia> Listar(Noticia pObjNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_NOTICIA"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; if (pObjNoticia.ID > 0) { objComando.Parameters.Add("@NoticiaId", SqlDbType.Int).Value = pObjNoticia.ID; } if (pObjNoticia.TipoArquivo != null && pObjNoticia.TipoArquivo.Id > 0) { objComando.Parameters.Add("@TipoNoticiaId", SqlDbType.Int).Value = pObjNoticia.TipoArquivo.Id; } if (pObjNoticia.IdiomaId > 0) { objComando.Parameters.Add("@IdiomaId", SqlDbType.Int).Value = pObjNoticia.IdiomaId; } try { objConexao.Open(); List <Noticia> listNoticia = new List <Noticia>(); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { Noticia obj = new Noticia(); obj.FromIDataReader(idrReader); listNoticia.Add(obj); } return(listNoticia); } catch (Exception ex) { throw ex; } }
public static Noticia Obter(Noticia pNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_NOTICIA"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; objComando.Parameters.Add("@NoticiaId", SqlDbType.Int).Value = pNoticia.ID; if (pNoticia.StatusId != null) { objComando.Parameters.Add("@StatusId", SqlDbType.Int).Value = pNoticia.StatusId; } try { objConexao.Open(); Noticia obj = new Noticia(); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { obj.FromIDataReader(idrReader); } return(obj); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }
public static Noticia ObterDestaqueHome(Noticia pObjNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_NOTICIA_DESTAQUE"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; if (pObjNoticia.TipoArquivo != null && pObjNoticia.TipoArquivo.Id > 0) { objComando.Parameters.Add("@tipoArquivoId", SqlDbType.Int).Value = pObjNoticia.TipoArquivo.Id; } try { objConexao.Open(); Noticia obj = new Noticia(); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { obj.FromIDataReader(idrReader); } return(obj); } catch (Exception ex) { throw ex; } }