public async Task <bool> SaveMagnifierSettings(GridSettingsDto settingsDto) { Contract.Requires(settingsDto != null); bool value = false; IMapper mapper = MapperField.GetMapper(); GRID_SERIALIZATION serialize = mapper.Map <GridSettingsDto, GRID_SERIALIZATION>(settingsDto); Contract.Requires(serialize != null); value = await SaveOrUpdate(serialize).ConfigureAwait(false); return(value); }
private async Task <bool> SaveOrUpdate(GRID_SERIALIZATION serialize) { bool value = false; using (var dbConnection = _executorSql.OpenNewDbConnection()) { using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { if (string.IsNullOrEmpty(serialize.GRID_NAME)) { serialize.GRID_NAME = "Unknown"; } if (dbConnection.IsPresent <GRID_SERIALIZATION>(serialize)) { // update string updateSql = string.Format(GenericSql.GridSettingsUpdate, serialize.GRID_ID, serialize.GRID_NAME, serialize.SERILIZED_DATA); try { value = await dbConnection.ExecuteAsync(updateSql) > 0; } catch (System.Exception e) { throw new DataLayerException(e.Message, e); } } else { string insertSql = string.Format(GenericSql.GridSettingInsert, serialize.GRID_ID, serialize.GRID_NAME, serialize.SERILIZED_DATA); var executedInsert = await dbConnection.ExecuteAsync(insertSql); value = executedInsert > 0; } transactionScope.Complete(); } catch (System.Exception e) { throw new DataLayerException(e.Message, e); } } } return(value); }