Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Currencies

Describes how to configure currencies used when configuring markets and placing orders.

Installation creates a list of currencies.

Classes in this topic are in the following namespaces:

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

Create currencies

The following example creates a Bitcoin currency and adds an exchange rate to USD:

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

The following example renames USD and adjusts an existing exchange rate:

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

The following example deletes a currency:

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