public async Task InsertOrReplaceAsync(IAccountTransactionsReport entity)
        {
            using (var conn = new SqlConnection(_settings.Db.ReportsSqlConnString))
            {
                try
                {
                    try
                    {
                        await conn.ExecuteAsync(
                            $"insert into {TableName} ({GetColumns}) values ({GetFields})", entity);
                    }
                    catch (SqlException)
                    {
                        await conn.ExecuteAsync(
                            $"update {TableName} set {GetUpdateClause} where Id=@Id", entity);
                    }
                }
                catch (Exception ex)
                {
                    var msg = $"Error {ex.Message} \n" +
                              "Entity <IAccountTransactionsReport>: \n" +
                              entity.ToJson();
                    await _log?.WriteWarningAsync("AccountTransactionsReportsSqlRepository", "InsertOrReplaceAsync", null, msg);

                    throw new Exception(msg);
                }
            }
        }
Esempio n. 2
0
 public async Task InsertOrReplaceAsync(IAccountTransactionsReport report)
 {
     foreach (var item in _repositories)
     {
         await item.InsertOrReplaceAsync(report);
     }
 }
        public async Task InsertOrReplaceAsync(IAccountTransactionsReport entity)
        {
            using (var conn = new SqlConnection(_settings.Db.ReportsSqlConnString))
            {
                var    res = conn.ExecuteScalar($"select Id from {TableName} where Id = '{entity.Id}'");
                string query;
                if (res == null)
                {
                    query = $"insert into {TableName} " +
                            "(Id, Date, AccountId, ClientId, Amount, Balance, WithdrawTransferLimit, Comment, Type, PositionId, LegalEntity, AuditLog) " +
                            " values " +
                            "(@Id ,@Date, @AccountId, @ClientId, @Amount, @Balance, @WithdrawTransferLimit, @Comment, @Type, @PositionId, @LegalEntity, @AuditLog)";
                }
                else
                {
                    query = $"update {TableName} set " +
                            "Date=@Date, AccountId=@AccountId, ClientId=@ClientId, Amount=@Amount, Balance=@Balance, " +
                            "WithdrawTransferLimit=@WithdrawTransferLimit, Comment=@Comment, Type=@Type, " +
                            "PositionId = @PositionId, LegalEntity = @LegalEntity, AuditLog = @AuditLog" +
                            " where Id=@Id";
                }
                try { await conn.ExecuteAsync(query, entity); }
                catch (Exception ex)
                {
                    var msg = $"Error {ex.Message} \n" +
                              "Entity <IAccountTransactionsReport>: \n" +
                              entity.ToJson();
                    await _log?.WriteWarningAsync("AccountTransactionsReportsSqlRepository", "InsertOrReplaceAsync", null, msg);

                    throw new Exception(msg);
                }
            }
        }
 public static AccountTransactionsReport ToDto(this IAccountTransactionsReport src)
 {
     return(new AccountTransactionsReport
     {
         AccountId = src.AccountId,
         Amount = src.Amount,
         Balance = src.Balance,
         ClientId = src.ClientId,
         Comment = src.Comment,
         Date = src.Date,
         Id = src.Id,
         PositionId = src.PositionId,
         Type = src.Type,
         WithdrawTransferLimit = src.WithdrawTransferLimit
     });
 }
 public Task InsertOrReplaceAsync(IAccountTransactionsReport entity)
 {
     return(_tableStorage.InsertOrReplaceAsync(AccountTransactionsReportsEntity.Create(entity)));
 }