Ejemplo n.º 1
0
 public List <Product> findall()
 {
     using (mydemoEntities mde = new mydemoEntities())
     {
         return(mde.Product.Select(pe => new Product
         {
             Id = pe.Id,
             Name = pe.Name,
             Price = pe.Price.Value,
             Quantity = pe.Quantity.Value
         }).ToList());
     };
 }
Ejemplo n.º 2
0
 public Product find(string id)
 {
     using (mydemoEntities mde = new mydemoEntities())
     {
         int nid = Convert.ToInt32(id);
         return(mde.Product.Where(pe => pe.Id == nid).Select(pe => new Product
         {
             Id = pe.Id,
             Name = pe.Name,
             Price = pe.Price.Value,
             Quantity = pe.Quantity.Value
         }).First());
     };
 }
Ejemplo n.º 3
0
 public bool delete(Product product)
 {
     using (mydemoEntities mde = new mydemoEntities())
     {
         try
         {
             int           id = Convert.ToInt32(product.Id);
             ProductEntity pe = mde.Product.Single(p => p.Id == id);
             mde.Product.Remove(pe);
             mde.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     };
 }
Ejemplo n.º 4
0
 public bool edit(Product product)
 {
     using (mydemoEntities mde = new mydemoEntities())
     {
         try
         {
             int           id = Convert.ToInt32(product.Id);
             ProductEntity pe = mde.Product.Single(p => p.Id == id);
             pe.Name     = product.Name;
             pe.Price    = product.Price;
             pe.Quantity = product.Quantity;
             mde.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     };
 }
Ejemplo n.º 5
0
 public bool create(Product product)
 {
     using (mydemoEntities mde = new mydemoEntities())
     {
         try
         {
             ProductEntity pe = new ProductEntity();
             pe.Name     = product.Name;
             pe.Price    = product.Price;
             pe.Quantity = product.Quantity;
             mde.Product.Add(pe);
             mde.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     };
 }