Example #1
0
 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;
             }
         }
     }
 }
Example #2
0
 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;
             }
         }
     }
 }
Example #3
0
 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;
             }
         }
     }
 }
Example #4
0
 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;
             }
         }
     }
 }