HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

Currencies

Describes how to configure currencies used when configuring markets and placing orders in Optimizely Customized Commerce 13.

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

Create 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);

Update 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);

Delete currencies

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