public static void Create(Pedido pd) { using (DeliveryEntities db = new DeliveryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { db.Pedido.Add(pd); db.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } }
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; } } } }
public static void Create(DetallePedido p) { using (DeliveryEntities db = new DeliveryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { p.Pedido.fechapedido = DateTime.Now; db.DetallePedido.Add(p); db.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } }