Currencies and exchange rates
List of examples:
Currencies
Creating a new currency
// Creates a new currency object
CurrencyInfo newCurrency = new CurrencyInfo();
// Sets the currency properties
newCurrency.CurrencyDisplayName = "New currency";
newCurrency.CurrencyName = "NewCurrency";
newCurrency.CurrencyCode = "NC";
newCurrency.CurrencySiteID = SiteContext.CurrentSiteID;
newCurrency.CurrencyEnabled = true;
newCurrency.CurrencyFormatString = "{0:F} NC";
newCurrency.CurrencyIsMain = false;
// Saves the currency to the database
CurrencyInfoProvider.SetCurrencyInfo(newCurrency);
Updating a currency
// Gets the currency
CurrencyInfo updateCurrency = CurrencyInfoProvider.GetCurrencyInfo("NewCurrency", SiteContext.CurrentSiteName);
if (updateCurrency != null)
{
// Updates the currency properties
updateCurrency.CurrencyDisplayName = updateCurrency.CurrencyDisplayName.ToLower();
// Saves the changes to the database
CurrencyInfoProvider.SetCurrencyInfo(updateCurrency);
}
Updating multiple currencies
// Gets all currencies whose code name starts with 'NewCurrency'
var currencies = CurrencyInfoProvider.GetCurrencies().WhereStartsWith("CurrencyName", "NewCurrency");
// Loops through the currency objects
foreach (CurrencyInfo modifyCurrency in currencies)
{
// Updates the currency properties
modifyCurrency.CurrencyDisplayName = modifyCurrency.CurrencyDisplayName.ToUpper();
// Saves the changes to the database
CurrencyInfoProvider.SetCurrencyInfo(modifyCurrency);
}
Deleting a currency
// Gets the currency
CurrencyInfo deleteCurrency = CurrencyInfoProvider.GetCurrencyInfo("NewCurrency", SiteContext.CurrentSiteName);
if (deleteCurrency != null)
{
// Deletes the currency
CurrencyInfoProvider.DeleteCurrencyInfo(deleteCurrency);
}
Exchange tables
Creating an exchange table
// Creates a new exchange table object
ExchangeTableInfo newTable = new ExchangeTableInfo();
// Sets the exchange table properties
newTable.ExchangeTableDisplayName = "New table";
newTable.ExchangeTableSiteID = SiteContext.CurrentSiteID;
newTable.ExchangeTableValidFrom = DateTime.Now;
newTable.ExchangeTableValidTo = DateTime.Now;
// Saves the exchange table to the database
ExchangeTableInfoProvider.SetExchangeTableInfo(newTable);
Updating an exchange table
// Gets the exchange table
ExchangeTableInfo updateTable = ExchangeTableInfoProvider.GetExchangeTableInfo("New table", SiteContext.CurrentSiteName);
if (updateTable != null)
{
// Sets the desired time
TimeSpan time = TimeSpan.FromDays(7);
// Updates the time validity properties
updateTable.ExchangeTableValidFrom = updateTable.ExchangeTableValidFrom.Add(time);
updateTable.ExchangeTableValidTo = updateTable.ExchangeTableValidTo.Add(time);
// Saves the changes to the database
ExchangeTableInfoProvider.SetExchangeTableInfo(updateTable);
}
Updating multiple exchange tables
// Gets all exchange tables assigned to the current site whose display name starts with 'New table'
var tables = ExchangeTableInfoProvider.GetExchangeTables()
.OnSite(SiteContext.CurrentSiteID)
.WhereStartsWith("ExchangeTableDisplayName", "New table");
// Prepares a 14 day time span for the exchange table validity
TimeSpan time = TimeSpan.FromDays(14);
// Loops through the exchange tables
foreach (ExchangeTableInfo modifyTable in tables)
{
// Updates the time validity properties
modifyTable.ExchangeTableValidFrom = modifyTable.ExchangeTableValidFrom.Add(time);
modifyTable.ExchangeTableValidTo = modifyTable.ExchangeTableValidTo.Add(time);
// Saves the changes to the database
ExchangeTableInfoProvider.SetExchangeTableInfo(modifyTable);
}
Deleting an exchange table
// Gets the exchange table
ExchangeTableInfo deleteTable = ExchangeTableInfoProvider.GetExchangeTableInfo("New table", SiteContext.CurrentSiteName);
if (deleteTable != null)
{
// Deletes the exchange table
ExchangeTableInfoProvider.DeleteExchangeTableInfo(deleteTable);
}