Table of Contents

Class CurrencyService

Namespace
Dynamicweb.Ecommerce.International
Assembly
Dynamicweb.Ecommerce.dll

Currency service provides operations for working with the currency model

public class CurrencyService : ICacheStorage<string, Currency>, ICacheStorage<string>, ICacheStorage
Inheritance
CurrencyService
Implements
Inherited Members

Properties

Info

Information about the object cache

public virtual CacheInformation Info { get; }

Property Value

CacheInformation

Methods

CleanDefault()

Remove default property from currencies.

public virtual void CleanDefault()

ClearCache()

Resets all keys to the default value for objects stored in the object cache

public virtual void ClearCache()

ClearCache(IEnumerable<string>)

Resets the specified keys to the default value for objects stored in the object cache

public virtual void ClearCache(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

Keys to reset

ClearCache(string)

Resets the specified key to the default value for objects stored in the object cache

public virtual void ClearCache(string key)

Parameters

key string

Key to reset

Delete(string)

Deletes an instance with the specified parameters.

public virtual void Delete(string currencyCode)

Parameters

currencyCode string

The currency code.

Format(Currency, double)

Formats the specified value according to the currency settings.

public virtual string Format(Currency currency, double value)

Parameters

currency Currency

The currency to use for formatting the value

value double

The value - the price to format to a string.

Returns

string

The formatted value.

Format(Currency, double, bool)

Formats the specified value according to the currency settings.

public virtual string Format(Currency currency, double value, bool showSymbol)

Parameters

currency Currency

The currency to use for formatting the value.

value double

The value - the price to format to a string.

showSymbol bool

If set to true, includes the currency symbol.

Returns

string

The formatted value as a string.

Examples

var currencyService = new CurrencyService();
var currency = currencyService.GetCurrency("USD");
string formattedValue = currencyService.Format(currency, 1234.56, true);
// formattedValue might be "$1,234.56" depending on the currency settings

Remarks

This method formats a given value according to the specified currency's settings. It takes into account the currency's culture info, rounding settings, and whether to show the currency symbol. If the currency's culture info is specified and contains a hyphen, it uses the NumberFormatInfo from the cache.

GetAllCurrencies()

Gets all currencies.

public virtual IEnumerable<Currency> GetAllCurrencies()

Returns

IEnumerable<Currency>

A collection of the Currency.

GetCurrency(string)

Gets a currency by currency code.

public virtual Currency? GetCurrency(string currencyCode)

Parameters

currencyCode string

The currency code.

Returns

Currency

An instance of Currency, if found, otherwise null.

GetCurrencyOrDefault(string)

Gets the currency by currency code. Returns the default currency if the selected currency is not found.

public virtual Currency GetCurrencyOrDefault(string currencyCode)

Parameters

currencyCode string

Currency code

Returns

Currency

GetDefaultCurrency()

Gets the default currency.

public virtual Currency GetDefaultCurrency()

Returns

Currency

A currency Currency.

GetOrCreateCurrency(string, string, double, string?)

Gets existed currency. If currency is not found, creates the custom currency based on currency data.

public virtual Currency GetOrCreateCurrency(string currencyCode, string currencyName, double currencyRate, string? languageId)

Parameters

currencyCode string

Currency code

currencyName string

Currency name

currencyRate double

Currency rate

languageId string

Language id

Returns

Currency

Returns the currency by currency code. If currency code is empty, returns null. If currency code is set, but nothing is found, returns custom currency.

Round(Currency, double)

Rounds the value.

public virtual double Round(Currency currency, double value)

Parameters

currency Currency
value double

The value.

Returns

double

The rounded value.

Save(Currency)

Saves a currency instance

public virtual void Save(Currency currency)

Parameters

currency Currency

The currency.

SetCacheType<TObjectCache>()

Changes the storage container

public virtual void SetCacheType<TObjectCache>() where TObjectCache : ServiceCache<string, Currency>

Type Parameters

TObjectCache

UpdateCurrencyCode(string, string)

Update currency and its relations with a new Code.

public virtual void UpdateCurrencyCode(string oldCode, string newCode)

Parameters

oldCode string

The old code.

newCode string

The new code.

To top