public async Task Dump(IEnumerable <Position> openPositions) { var reportTime = _dateService.Now(); var entities = openPositions.Select(x => OpenPositionEntity.Create(x, reportTime)); await _tableStorage.DeleteAsync(); await _tableStorage.CreateTableIfNotExistsAsync(); await _tableStorage.InsertAsync(entities); }
public async Task Dump(IEnumerable <Position> openPositions) { var reportTime = _dateService.Now(); var entities = openPositions.Select(x => OpenPositionEntity.Create(x, reportTime)); using (var conn = new SqlConnection(_connectionString)) { if (conn.State == ConnectionState.Closed) { await conn.OpenAsync(); } var transaction = conn.BeginTransaction(); try { await conn.ExecuteAsync( $"TRUNCATE TABLE {TableName}", new {}, transaction); await conn.ExecuteAsync( $"INSERT INTO {TableName} ({GetColumns}) VALUES ({GetFields})", entities, transaction); transaction.Commit(); } catch (Exception ex) { await _log.WriteWarningAsync(nameof(AccountMarginFreezingRepository), nameof(Dump), $"Failed to dump open positions data at {_dateService.Now():s}", ex); transaction.Rollback(); throw; } } }