/// <summary> /// Returns the default currency. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <returns> /// The default currency. /// </returns> internal static CurrencyViewModel GetDefaultCurrency(IRepositoryFactory repositoryFactory) { Currency currencyDto; using (var repository = repositoryFactory.GetSettingRepository()) { currencyDto = repository.FirstOrDefault(s => !s.IsDeleted)?.DefaultCurrency; } return(ModelsMapper.GetCurrencyViewModel(currencyDto)); }
/// <summary> /// Tries to convert price to price in the specified currency via a cross-cource. /// </summary> /// <param name="repository"> /// The currency rates repository. /// </param> /// <param name="amount"> /// The price amount. /// </param> /// <param name="currencyCode"> /// The currency code. /// </param> /// <param name="targetCurrencyCode"> /// The target currency code. /// </param> /// <param name="targetPrice"> /// The convertion result. /// </param> internal static bool TryConvertToTargetPrice( ICurrencyRateRepository repository, decimal amount, int currencyCode, int targetCurrencyCode, out PriceViewModel targetPrice) { var rate = GetCurrencyRate(repository, currencyCode, targetCurrencyCode); if (rate != null) { targetPrice = new PriceViewModel { // financial rounding to even Amount = Math.Round(rate.CrossCourse * amount, 2, MidpointRounding.ToEven), Currency = ModelsMapper.GetCurrencyViewModel(rate.TargetCurrency) }; return(true); } targetPrice = null; return(false); }