Ejemplo n.º 1
0
 public IEnumerable <Product> GetAllProducts()
 {
     using (var db = new ProductsDBEntities())
     {
         return(db.Products.ToList());
     }
 }
Ejemplo n.º 2
0
 public void CreateProduct(Product product)
 {
     using (var db = new ProductsDBEntities())
     {
         db.Products.Add(product);
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void DeleteProduct(int id)
 {
     using (var db = new ProductsDBEntities())
     {
         var entity = db.Products.SingleOrDefault(p => p.Id == id);
         db.Products.Remove(entity);
         db.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public List <Product> GetProductbyId(int id)
 {
     using (var db = new ProductsDBEntities())
     {
         // thats way using sp !!!
         //var byCat = db.GetProductaByCategory("gghghg");
         return(db.Products.Where(p => p.Id == id).ToList());
     }
 }
Ejemplo n.º 5
0
 public void UpdateProduct(int id, Product product)
 {
     using (var db = new ProductsDBEntities())
     {
         var entity = db.Products.SingleOrDefault(p => p.Id == id);
         entity.Name     = product.Name;
         entity.Price    = product.Price;
         entity.Category = product.Category;
         db.SaveChanges();
     }
 }