コード例 #1
0
 public async Task<StoreModel> LoadStore(long id)
 {
     StoreModel store = null;
     try
     {
         using (var db = dbManager.GetConnection())
         using (var command = db.Connection.CreateCommand())
         {
             command.CommandText = string.Format("SELECT * FROM STORE WHERE Id = {0}", id);
             var dbReader = await command.ExecuteReaderAsync().ConfigureAwait(false);
             if (dbReader.HasRows && dbReader.Read())
             {
                 store = new StoreModel
                 {
                     Id = dbReader.GetInt64(0),
                     Name = dbReader.GetString(1)
                 };
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error("Exception during execution method \"LoadStore\": {0}", ex.Message);
     }
     return store;
 }
コード例 #2
0
 public async Task<long> SaveStore(StoreModel store)
 {
     long storeId = -1;
     try
     {
         using (var db = dbManager.GetConnection())
         using (var command = db.Connection.CreateCommand())
         {
             if (store.Id == 0)
             {
                 command.CommandText = string.Format("SELECT Id FROM STORE WHERE Name='{0}'", store.Name);
                 storeId = (long)(await command.ExecuteScalarAsync().ConfigureAwait(false) ?? 0L);
             }
             else
             {
                 storeId = store.Id;
             }
             if (storeId == 0)
             {
                 command.CommandText = string.Format("INSERT INTO STORE(Name) VALUES ('{0}'); SELECT last_insert_rowid() FROM STORE", store.Name);
                 storeId = (long)(await command.ExecuteScalarAsync().ConfigureAwait(false));
             }
             else
             {
                 command.CommandText = string.Format("UPDATE STORE SET Name = '{0}' WHERE Id = {1}", store.Name, storeId);
                 await command.ExecuteNonQueryAsync().ConfigureAwait(false);
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error("Exception during execution method \"SaveStore\": {0}", ex.Message);
     }
     return storeId;
 }