HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Currencies

This topic describes how to configure currencies used when configuring markets and placing orders.

On install, a complete list of paper currencies is created.

Classes in this topic are in the following namespaces:

  • Mediachase.Commerce.Catalog.Dto
  • Mediachase.Commerce.Catalog.Managers

Working with currencies

Creating currencies

var existingCurrencies = CurrencyManager.GetCurrencyDto();
    var dto = new CurrencyDto();
    var currencyRow = dto.Currency.NewCurrencyRow();
    currencyRow.Name = "Bitcoin";
    currencyRow.CurrencyCode = "BTC";
    currencyRow.ModifiedDate = DateTime.UtcNow;
    
    if (currencyRow.RowState == DataRowState.Detached)
        dto.Currency.Rows.Add(currencyRow);
    
    var rateRow = dto.CurrencyRate.NewCurrencyRateRow();
    rateRow.FromCurrencyId = dto.Currency[0].CurrencyId;
    rateRow.ToCurrencyId = existingCurrencies.Currency.First(x => x.CurrencyCode.Equals("USD")).CurrencyId;
    rateRow.EndOfDayRate = 50000;
    rateRow.AverageRate = 50000;
    rateRow.CurrencyRateDate = DateTime.Now.Date;
    rateRow.ModifiedDate = DateTime.UtcNow;
    
    if (rateRow.RowState == DataRowState.Detached)
        dto.CurrencyRate.AddCurrencyRateRow(rateRow);
    
    CurrencyManager.SaveCurrency(dto);

Updating currencies

var dto = CurrencyManager.GetCurrencyDto();
    var currencyRow = dto.Currency.FirstOrDefault(x => x.CurrencyCode.Equals("USD"));
    currencyRow.Name = "USA Dollar";
    currencyRow.ModifiedDate = DateTime.UtcNow;
    var rateRow = currencyRow.GetCurrencyRateRows().FirstOrDefault(x => x.FromCurrencyId == dto.Currency.FirstOrDefault(x => x.CurrencyCode.Equals("BTC")).CurrencyId);
    rateRow.EndOfDayRate = 55000;
    rateRow.AverageRate = 49000;
    rateRow.CurrencyRateDate = DateTime.Now.Date;
    rateRow.ModifiedDate = DateTime.UtcNow;
    CurrencyManager.SaveCurrency(dto);

Deleting currencies

var dto = CurrencyManager.GetCurrencyDto();
    var currencyRow = dto.Currency.FirstOrDefault(x => x.CurrencyCode.Equals("USD"));
    currencyRow.Delete();
    CurrencyManager.SaveCurrency(dto);

Did this page help you?