コード例 #1
0
 public void Add(Product product)
 {
     using (var db = new ProductCatalogDBEntities())
     {
         db.Products.Add(product);
         db.SaveChanges();
     }
 }
コード例 #2
0
 public void Delete(int id)
 {
     using (var db = new ProductCatalogDBEntities())
     {
         var prod = db.Products.FirstOrDefault(p => p.Id == id);
         db.Products.Remove(prod);
         db.SaveChanges();
     }
 }
コード例 #3
0
 public void Update(Product product)
 {
     using (var db = new ProductCatalogDBEntities())
     {
         var prod = db.Products.FirstOrDefault(p => p.Id == product.Id);
         if (prod != null)
         {
             prod.Name        = product.Name;
             prod.Photo       = product.Photo;
             prod.Price       = product.Price;
             prod.LastUpdated = product.LastUpdated;
             db.SaveChanges();
         }
     }
 }