public bool update(Products entity) { using (var db = new ProductWithQRCodeDbContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try{ db.Products.Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch (Exception) { dbContextTransaction.Rollback(); return(false); } } } }
public bool delete(int _proId) { using (var db = new ProductWithQRCodeDbContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var product = db.Products.SingleOrDefault(x => x.ID == _proId); product.Status = false; db.Products.Attach(product); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch (Exception) { dbContextTransaction.Rollback(); return(false); } } } }
public int Delete(int _cateId) { using (var db = new ProductWithQRCodeDbContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var category = db.Categories.Find(_cateId); category.Status = false; db.Categories.Attach(category); db.Entry(category).State = EntityState.Modified; db.SaveChanges(); dbContextTransaction.Commit(); return((int)category.Type); } catch (Exception) { dbContextTransaction.Rollback(); return(0); } } } }