public async Task InsertAsync(IAccountHistory report) { foreach (var item in _repositories) { await item.InsertAsync(report); } }
public async Task InsertAsync(IAccountHistory obj) { var entity = _convertService.Convert <AccountHistoryEntity>(obj); using (var conn = new SqlConnection(_settings.Db.ConnString)) { if (conn.State == ConnectionState.Closed) { await conn.OpenAsync(); } var transaction = conn.BeginTransaction(IsolationLevel.Serializable); try { await conn.ExecuteAsync($"INSERT INTO [dbo].[AccountHistory] ({GetColumns}) VALUES ({GetFields})", entity, transaction); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); var msg = $"Error {ex.Message} \n" + "Entity <AccountHistoryEntity>: \n" + entity.ToJson(); _log?.WriteError(nameof(AccountHistoryRepository), nameof(InsertAsync), new Exception(msg)); throw; } } #pragma warning disable 4014 Task.Run(async() => #pragma warning restore 4014 { try { if (string.IsNullOrWhiteSpace(obj.EventSourceId) && new[] { AccountBalanceChangeReasonType.Commission, AccountBalanceChangeReasonType.OnBehalf, AccountBalanceChangeReasonType.Tax, }.Contains(obj.ReasonType)) { throw new Exception($"EventSourceId was null, with reason type {obj.ReasonType}"); } using (var conn = new SqlConnection(_settings.Db.ConnString)) { await conn.ExecuteAsync("[dbo].[UpdateDealCommissionParamsOnAccountHistory]", new { ChangeAmount = obj.ChangeAmount, ReasonType = obj.ReasonType.ToString(), EventSourceId = obj.EventSourceId, }, commandType: CommandType.StoredProcedure); } } catch (Exception exception) { if (_log != null) { await _log.WriteErrorAsync(nameof(AccountHistoryRepository), nameof(InsertAsync), new Exception($"Failed to calculate commissions for eventSourceId {obj.EventSourceId} with reasonType {obj.ReasonType}, skipping.", exception)); } } }); }
public Account(IClient client, IAccountHistory history) { Client = client; History = history; Balance = computeBalance(); }
public Task InsertAsync(IAccountHistory obj) { var entity = _convertService.Convert <AccountHistoryEntity>(obj); return(_tableStorage.InsertOrReplaceAsync(entity)); }