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
CurrencyInfo.Provider.Set(newCurrency);

> Back to list of examples

Updating a currency



// Gets the currency
CurrencyInfo updateCurrency = CurrencyInfo.Provider.Get("NewCurrency", SiteContext.CurrentSiteID);
if (updateCurrency != null)
{
    // Updates the currency properties
    updateCurrency.CurrencyDisplayName = updateCurrency.CurrencyDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    CurrencyInfo.Provider.Set(updateCurrency);
}

> Back to list of examples

Updating multiple currencies



// Gets all currencies whose code name starts with 'NewCurrency'
var currencies = CurrencyInfo.Provider.Get().WhereStartsWith("CurrencyName", "NewCurrency");

// Loops through the currency objects
foreach (CurrencyInfo modifyCurrency in currencies)
{
    // Updates the currency properties
    modifyCurrency.CurrencyDisplayName = modifyCurrency.CurrencyDisplayName.ToUpperCSafe();

    // Saves the changes to the database
    CurrencyInfo.Provider.Set(modifyCurrency);
}

> Back to list of examples

Deleting a currency



// Gets the currency
CurrencyInfo deleteCurrency = CurrencyInfo.Provider.Get("NewCurrency", SiteContext.CurrentSiteID);
if (deleteCurrency != null)
{
    // Deletes the currency
    CurrencyInfo.Provider.Delete(deleteCurrency);
}

> Back to list of examples

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
ExchangeTableInfo.Provider.Set(newTable);

> Back to list of examples

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
    ExchangeTableInfo.Provider.Set(updateTable);
}

> Back to list of examples

Updating multiple exchange tables



// Gets all exchange tables assigned to the current site whose display name starts with 'New table'
var tables = ExchangeTableInfo.Provider.Get()
                                        .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
    ExchangeTableInfo.Provider.Set(modifyTable);
}

> Back to list of examples

Deleting an exchange table



// Gets the exchange table
ExchangeTableInfo deleteTable = ExchangeTableInfoProvider.GetExchangeTableInfo("New table", SiteContext.CurrentSiteName);

if (deleteTable != null)
{
    // Deletes the exchange table
    ExchangeTableInfo.Provider.Delete(deleteTable);
}

> Back to list of examples