public void Edit(MobilesVM mob) { var data = mapper.Map <Mobiles>(mob); db.Entry(data).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Delete(DbContainer db, string[] deleteCollection) { var collection = (from f in db.SysLog where deleteCollection.Contains(f.ID) select f).ToList(); collection.ForEach(item => { db.Entry(item).State = System.Data.Entity.EntityState.Deleted; db.SysLog.Remove(item); }); db.SaveChanges(); }
public virtual bool Edit(T model) { if (db.Entry <T>(model).State == EntityState.Modified) { return(db.SaveChanges() > 0); } else if (db.Entry <T>(model).State == EntityState.Detached) { try { db.Set <T>().Attach(model); db.Entry <T>(model).State = EntityState.Modified; } catch (InvalidOperationException) { //T old = Find(model._ID); //db.Entry<old>.CurrentValues.SetValues(model); return(false); } return(db.SaveChanges() > 0); } return(false); }
public int Delete(int id) { using (DbContainer db = new DbContainer()) { var entity = GetById(id); if (entity != null) { //改变实体状态,否则无法删除(报错) db.Entry(entity).State = EntityState.Deleted; db.Set<SysSample>().Remove(entity); } return db.SaveChanges(); } }
public bool Delete(string id) { using (DbContainer db = new DbContainer()) { var entity = GetById(id); if (entity != null) { db.Entry(entity).State = System.Data.Entity.EntityState.Deleted; db.SysException.Remove(entity); return(db.SaveChanges() > 0); } return(false); } }
public int Edit(SysSample entity) { try { using (DbContainer db = new DbContainer()) { db.Set<SysSample>().Attach(entity); db.Entry(entity).State = EntityState.Modified; return db.SaveChanges(); } } catch (Exception ex) { return 0; } }
public ActionResult Edit(int id, Customer customer) { if (customer != null) { Customer customerInDb = _container.customers.Find(id); if (customerInDb != null) { customerInDb.Name = customer.Name; customerInDb.Address = customer.Address; customerInDb.PhoneNumber = customer.PhoneNumber; _container.Entry(customerInDb).State = EntityState.Modified; _container.SaveChanges(); TempData["Success"] = "Modify Customer Successed!"; return(RedirectToAction("index")); } } else { TempData["Error"] = "This Customer Not Found!"; return(RedirectToAction("index")); } return(View()); }