Exemplo n.º 1
0
 public Product Product(int id)
 {
     try
     {
         Product Product = null;
         try
         {
             // Se prepara la consulta de selección para obtener un único producto,
             // el especificado por su ID.
             string             sql       = "SELECT * FROM dbo.Products WHERE Id = @Id";
             List <DbParameter> ParamList = new List <DbParameter>();
             SqlParameter       p1        = new SqlParameter("@Id", SqlDbType.VarChar);
             p1.Value = id;
             ParamList.Add(p1);
             DataTable dt = _dataAccess.Read(sql, ParamList);
             if (dt.Rows.Count > 0)
             {
                 Product = DBList.ToList <Product>(dt).First();
             }
         }
         catch (Exception)
         {
             throw;
         }
         return(Product);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
 public List <Product> Products()
 {
     try
     {
         List <Product> ct = null;
         try
         {
             // Se prepara la consulta de selección
             // y se convierten los datos obtenidos en una lista de productos.
             string             sql       = "SELECT * FROM dbo.Products";
             List <DbParameter> ParamList = new List <DbParameter>();
             DataTable          dt        = _dataAccess.Read(sql, ParamList);
             ct = DBList.ToList <Product>(dt);
         }
         catch (Exception)
         {
             throw;
         }
         return(ct);
     }
     catch (Exception)
     {
         throw;
     }
 }