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; } }
public bool editCategory(Category cat) { var db = new ProductContext(); if(cat != null) { db.Entry(cat).State = EntityState.Modified; db.SaveChanges(); return true; } return false; }
public bool addCategory(Category cat) { var db = new ProductContext(); if(cat != null) { db.Categories.Add(cat); db.SaveChanges(); return true; } return false; }
public bool addOrder(Order order) { var db = new ProductContext(); if(order != null) { db.Orders.Add(order); db.SaveChanges(); return true; } return false; }
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; }
public bool addProduct(Product product) { ProductContext db = new ProductContext(); if(product != null) { db.Products.Add(product); db.SaveChanges(); return true; } else { return false; } }
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; } }
public bool save() { var db = new ProductContext(); db.SaveChanges(); return true; }