示例#1
0
 public virtual T FindById(int id)
 {
     using (var db = new ContextDB.IncidencPlusDBContext())
     {
         return(db.Set <T>().Where(_ => _.Id == id).FirstOrDefault());
     }
 }
示例#2
0
 public virtual List <T> GetAll()
 {
     using (var db = new ContextDB.IncidencPlusDBContext())
     {
         //return db.Set<T>().Where(_ => _.State == StateEntity.ACTIVE).ToList();
         return(db.Set <T>().ToList());
     }
 }
示例#3
0
 public virtual void Add(T entity)
 {
     using (var db = new ContextDB.IncidencPlusDBContext())
     {
         db.Set <T>().Add(entity);
         db.SaveChanges();
     }
 }
示例#4
0
 public virtual void Update(T entity)
 {
     using (var db = new ContextDB.IncidencPlusDBContext())
     {
         try
         {
             db.Database.BeginTransaction();
             db.Entry <T>(entity).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             db.Database.CurrentTransaction.Commit();
         }
         catch
         {
             db.Database.CurrentTransaction.Rollback();
         }
     }
 }
示例#5
0
 public virtual void Enable(int id)
 {
     using (var db = new ContextDB.IncidencPlusDBContext())
     {
         try
         {
             db.Database.BeginTransaction();
             var result = db.Set <T>().Where(_ => _.Id == id).FirstOrDefault();
             result.State = StateEntity.ACTIVE;
             db.SaveChanges();
             db.Database.CurrentTransaction.Commit();
         }
         catch
         {
             db.Database.CurrentTransaction.Rollback();
         }
     }
 }
示例#6
0
        public virtual void Delete(int id)
        {
            using (var db = new ContextDB.IncidencPlusDBContext())
            {
                try
                {
                    db.Database.BeginTransaction();
                    var _entityTemp = db.Set <T>().Where(_ => _.Id == id).FirstOrDefault();
                    _entityTemp.State = StateEntity.DELETED;
                    db.SaveChanges();

                    db.Database.CurrentTransaction.Commit();
                }
                catch
                {
                    db.Database.CurrentTransaction.Rollback();
                }
            }
        }