Пример #1
0
        public bool editProduct(Product product)
        {
            ProductContext db = new ProductContext();
            if(product != null)
            {
                db.Entry(product).State = EntityState.Modified;
                //db.SaveChanges();
                bool saveFailed;
                do
                {
                    saveFailed = false;

                    try
                    {
                       db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        saveFailed = true;

                        // Update the values of the entity that failed to save from the store
                        ex.Entries.Single().Reload();
                    }

                } while (saveFailed);
                return true;
            }
            else
            {
                return false;
            }
        }
Пример #2
0
 public bool editCategory(Category cat)
 {
     var db = new ProductContext();
     if(cat != null)
     {
         db.Entry(cat).State = EntityState.Modified;
         db.SaveChanges();
         return true;
     }
     return false;
 }
Пример #3
0
 public bool addCategory(Category cat)
 {
     var db = new ProductContext();
     if(cat != null)
     {
         db.Categories.Add(cat);
         db.SaveChanges();
         return true;
     }
     return false;
 }
Пример #4
0
 public bool addOrder(Order order)
 {
     var db = new ProductContext();
     if(order != null)
     {
         db.Orders.Add(order);
         db.SaveChanges();
         return true;
     }
     return false;
 }
Пример #5
0
 public bool deleteCategory(int? id)
 {
     var db = new ProductContext();
     Category cat = db.Categories.Find(id);
     if(cat != null)
     {
         db.Categories.Remove(cat);
         db.SaveChanges();
         return true;
     }
     return false;
 }
Пример #6
0
 public bool addProduct(Product product)
 {
     ProductContext db = new ProductContext();
     if(product != null)
     {
         db.Products.Add(product);
         db.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #7
0
 public bool deleteProduct(int? id)
 {
     ProductContext db = new ProductContext();
     Product product = db.Products.Find(id);
     if(product != null)
     {
         db.Products.Remove(product);
         db.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #8
0
 public bool save()
 {
     var db = new ProductContext();
     db.SaveChanges();
     return true;
 }