public static void Delete(int?id) { using (DeliveryEntities db = new DeliveryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { Pedido pd = db.Pedido.Find(id); db.Entry(pd).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public static void Update(Pedido pd) { using (DeliveryEntities db = new DeliveryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { db.Pedido.Attach(pd); db.Entry(pd).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }