示例#1
0
 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);
             }
         }
     }
 }
示例#2
0
 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);
             }
         }
     }
 }
示例#3
0
 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);
             }
         }
     }
 }