Пример #1
0
 public List <T> GetAllItems <T> () where T : class, new()
 {
     lock (SqlLock) {
         try {
             return(_dbConnection.Table <T> ().ToList());
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "GetAllItems");
         }
     }
 }
Пример #2
0
 public T GetItemById <T> (int id) where T : class, new()
 {
     lock (SqlLock) {
         try {
             return(_dbConnection.Get <T> (id));
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "GetItemById");
         }
     }
 }
Пример #3
0
 public void CleanupDB()
 {
     lock (SqlLock) {
         try {
             ResetTable <Settings> ();
             //add more tables here
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "CleanupDB");
         }
     }
 }
Пример #4
0
 public int ResetTable <T> () where T : class, new()
 {
     lock (SqlLock) {
         try {
             int ret = _dbConnection.DropTable <T> ();
             ret += _dbConnection.CreateTable <T> ();
             return(ret);
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "ResetTable");
         }
     }
 }
Пример #5
0
 public void RemoveItem <T> (int id) where T : class, new()
 {
     lock (SqlLock) {
         try {
             int ret = _dbConnection.Delete <T> (id);
             if (ret < 1)
             {
                 throw new MomSqlException("Could not insert item");
             }
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "RemoveItem");
         }
     }
 }
Пример #6
0
 public void InsertOrUpdateItem <T> (T item) where T : class, new()
 {
     lock (SqlLock) {
         try {
             int ret = _dbConnection.InsertOrReplace(item);
             if (ret < 1)
             {
                 throw new MomSqlException("Could not insert item");
             }
         } catch (Exception ex) {
             throw MomSqlException.ToMomException(ex, "InsertOrUpdateItem");
         }
     }
 }