Skip to content

Feat(admin/currencies): add CurrencyRate field and bulk rate update#1525

Open
suatsuphi wants to merge 1 commit into
smartstore:mainfrom
suatsuphi:main
Open

Feat(admin/currencies): add CurrencyRate field and bulk rate update#1525
suatsuphi wants to merge 1 commit into
smartstore:mainfrom
suatsuphi:main

Conversation

@suatsuphi

@suatsuphi suatsuphi commented Apr 20, 2026

Copy link
Copy Markdown
Contributor
  • Introduced CurrencyRate property in ExchangeRate and CurrencyModel
  • Updated CurrencyController logic to handle CurrencyRate recalculation with epsilon tolerance
  • Added ApplyRatesToAllCurrencies action for live bulk rate updates
  • Extended admin grid views (_Grid.Currencies, _Grid.LiveRates) to display and edit CurrencyRate
  • Included confirm prompt and toolbar button for bulk rate application

Language resource additions for currency rate updates
Admin.Configuration.Currencies.ApplyRatesToAll → Action key for applying exchange rates to all currencies.

Admin.Configuration.Currencies.Q_ApplyRatesToAll → Confirmation message key: “Exchange rates will be applied to all currencies. Do you want to continue?”

Admin.Configuration.Currencies.Fields.CurrencyRate → Field label key for displaying the conversion currency rate.

image
/// <summary>
/// **The conversion currency rate of this currency from the base currency**
/// </summary>
public decimal CurrencyRate { get; set; } = 1.0m;

/// <summary>
/// **The conversion rate of this currency from the base currency**
/// </summary>
public decimal Rate { get; set; } = 1.0m;
  • The Central Bank of Turkey publishes exchange rates on a daily basis. It does not provide rates!
    model.CurrencyRate = model.Rate == 0 ? 0 : 1.0M / model.Rate;

  • The Currency Rate can be saved on the _Grid.Currencies.cshtml page... If a Currency Rate has been entered, the rate can be calculated.

Code - CurrencyUpdate
[HttpPost]
[Permission(Permissions.Configuration.Currency.Update)]
public async Task<IActionResult> CurrencyUpdate(CurrencyModel model)
{
    var success = false;
    var currency = await _db.Currencies.FindByIdAsync(model.Id);

    if (currency != null)
    {
        try
        {
            **
            decimal exchangeRate = currency.Rate == 0 ? 0 : 1.0M / currency.Rate;
            const decimal epsilon = 0.00000001M; // builder.Property(c => c.Rate).HasPrecision(18, 8);
            if (Math.Abs(model.CurrencyRate - exchangeRate) > epsilon)
            {
                model.Rate = 1.0M / model.CurrencyRate;
            }
            **

            await MapperFactory.MapAsync(model, currency);
            await _db.SaveChangesAsync();
            success = true;
        }
        catch (Exception ex)
        {
            NotifyError(ex);
        }
    }

    return Json(new { success });
}

  • You can save the rates to the 'Currencies' section as 'Live currency rates' using the 'Apply rates to all' button.
Code - ApplyRatesToAllCurrencies ```
    [HttpPost]
    [Permission(Permissions.Configuration.Currency.EditExchangeRate)]
    public async Task<IActionResult> ApplyRatesToAllCurrencies(GridCommand command)
    {
        List<ExchangeRate> rates = (await Services.CurrencyService
            .GetCurrencyLiveRatesAsync(!command.InitialRequest))
            .ToList();

        var currencies = await _db.Currencies.ToListAsync();

        foreach (var currency in currencies)
        {
            var rateInfo = rates.FirstOrDefault(r => r.CurrencyCode == currency.CurrencyCode);
            if (rateInfo != null && rateInfo.Rate > 0)
            {
                currency.Rate = rateInfo.Rate;
                currency.UpdatedOnUtc = DateTime.UtcNow;
            }
        }

        await _db.SaveChangesAsync();
        NotifySuccess(T("Admin.Common.TaskSuccessfullyProcessed"));
        return RedirectToAction(nameof(Index));
    }

</details>



- Added `CurrencyRate` property to ExchangeRate and CurrencyModel for visual display
- Implemented simple calculation: CurrencyRate = (Rate == 0 ? 0 : 1 / Rate)
- Updated CurrencyUpdate logic to recalc Rate when CurrencyRate differs (epsilon tolerance)
- Introduced "ApplyRatesToAll" button to update all currencies with live exchange rates
- Added UI confirm prompt for bulk rate application
@mgesing

mgesing commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Why is ApplyRatesToAllCurrencies necessary? What benefit does it provide? It seems to do the same thing as UpdateExchangeRateTask.

@suatsuphi

suatsuphi commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

The user doesn’t want to update exchange rates automatically. If they want to update the rates on that particular day, they have to go to TASK, find ‘Update Currencies’ and run it manually. There is no 'Update Exchange Rate' button in the exchange rate section - just one by one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants