Ejemplo n.º 1
0
 public static void Create(Libro a)
 {
     using (DBBIBLIOTECAEntities db = new DBBIBLIOTECAEntities())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Libroes.Add(a);
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
Ejemplo n.º 2
0
 public static void Delete(int?id)
 {
     using (DBBIBLIOTECAEntities db = new DBBIBLIOTECAEntities())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 Libro libro = db.Libroes.Find(id);
                 db.Entry(libro).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static void Update(Libro libro)
 {
     using (DBBIBLIOTECAEntities db = new DBBIBLIOTECAEntities())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Libroes.Attach(libro);
                 db.Entry(libro).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }