private async Task SaveBankTransferFeeAsync(Collation collation,
                                             CollationSearch option,
                                             DateTime updateAt,
                                             CancellationToken token = default(CancellationToken))
 {
     if (collation.CustomerId > 0)
     {
         var fee = new CustomerFee {
             CustomerId = collation.CustomerId,
             CurrencyId = collation.CurrencyId,
             Fee        = collation.BankTransferFee,
             NewFee     = collation.BankTransferFee,
             UpdateAt   = updateAt,
             CreateAt   = updateAt,
             CreateBy   = option.LoginUserId,
             UpdateBy   = option.LoginUserId,
         };
         await addCustomerFeeQueryProcessor.SaveAsync(fee, token);
     }
     if (collation.PaymentAgencyId > 0)
     {
         var fee = new PaymentAgencyFee {
             PaymentAgencyId = collation.PaymentAgencyId,
             CurrencyId      = collation.CurrencyId,
             Fee             = collation.BankTransferFee,
             NewFee          = collation.BankTransferFee,
             UpdateAt        = updateAt,
             CreateAt        = updateAt,
             CreateBy        = option.LoginUserId,
             UpdateBy        = option.LoginUserId,
         };
         await addPaymentAgencyFeeQueryProcessor.SaveAsync(fee, token);
     }
 }
 private async Task SaveBankTransferFeeAsync(int customerId, int paymentAgencyId,
                                             int currencyId, decimal bankFee, DateTime updateAt, int loginUserId,
                                             CancellationToken token = default(CancellationToken))
 {
     if (bankFee == 0M)
     {
         return;
     }
     if (customerId != 0)
     {
         var fee = new CustomerFee();
         fee.CustomerId = customerId;
         fee.CurrencyId = currencyId;
         fee.Fee        = bankFee;
         fee.NewFee     = bankFee;
         fee.UpdateAt   = updateAt;
         fee.CreateAt   = updateAt;
         fee.CreateBy   = loginUserId;
         fee.UpdateBy   = loginUserId;
         await addCustomerFeeQueryProcessor.SaveAsync(fee, token);
     }
     if (paymentAgencyId != 0)
     {
         var fee = new PaymentAgencyFee();
         fee.PaymentAgencyId = paymentAgencyId;
         fee.CurrencyId      = currencyId;
         fee.Fee             = bankFee;
         fee.NewFee          = bankFee;
         fee.UpdateAt        = updateAt;
         fee.CreateAt        = updateAt;
         fee.CreateBy        = loginUserId;
         fee.UpdateBy        = loginUserId;
         await addPaymentAgencyFeeQueryProcessor.SaveAsync(fee, token);
     }
 }
        public Task <PaymentAgencyFee> SaveAsync(PaymentAgencyFee fee, CancellationToken token = default(CancellationToken))
        {
            var query = @"
MERGE INTO PaymentAgencyFee target
USING (
    SELECT @PaymentAgencyId     [PaymentAgencyId]
         , @CurrencyId          [CurrencyId]
         , @Fee                 [Fee]
      ) source
ON    (
        target.PaymentAgencyId      = source.PaymentAgencyId
    AND target.CurrencyId           = source.CurrencyId
    AND target.Fee                  = source.Fee
)
WHEN MATCHED THEN
    UPDATE
       SET UpdateBy     = @UpdateBy
         , UPdateAt     = GETDATE()
WHEN NOT MATCHED THEN
    INSERT
    ( PaymentAgencyId,  CurrencyId,  Fee,  CreateBy, CreateAt, UpdateBy, UpdateAt)
    VALUES
    (@PaymentAgencyId, @CurrencyId, @Fee, @CreateBy, GETDATE(), @UpdateBy, GETDATE())
OUTPUT inserted.*;
";

            return(dbHelper.ExecuteAsync <PaymentAgencyFee>(query, fee, token));
        }