Example #1
0
        public virtual void Delete <T>(T entity, bool isSubmit) where T : class
        {
            if (isSubmit && _dbEntities == null)
            {
                using (DbEntities db = new DbEntities())
                {
                    var obj = db.Set <T>();
                    if (entity != null)
                    {
                        obj.Attach(entity);
                        db.Entry(entity).State = System.Data.EntityState.Deleted;
                        obj.Remove(entity);
                        db.SaveChanges();
                    }
                }
            }
            else
            {
                _dbEntities.Set <T>().Attach(entity);
                _dbEntities.Entry(entity).State = System.Data.EntityState.Deleted;
                _dbEntities.Set <T>().Remove(entity);

                _dbEntities.SaveChanges();
            }
        }
Example #2
0
 public virtual T Insert <T>(T entity, bool isSubmit) where T : class
 {
     if (isSubmit && _dbEntities == null)
     {
         using (DbEntities db = new DbEntities())
         {
             var obj    = db.Set <T>();
             T   result = obj.Add(entity);
             db.SaveChanges();
             return(result);
         }
     }
     else
     {
         _dbEntities.Entry(entity);
         T result = _dbEntities.Set <T>().Add(entity);
         _dbEntities.SaveChanges();
         return(result);
     }
 }