public void OutputBalanceInCurrency(string currencyCode) { var totalCurrencyAmount = new CurrencyAmount(currencyCode, 0); var amounts = _transactionRepository.GetTransactions() .Select(t => t.Amount) .Select(a => a.CurrencyCode != currencyCode ? _currencyConverter.ConvertCurrency(a, currencyCode) : a) .ToArray(); var totalBalanceAmount = amounts.Aggregate(totalCurrencyAmount, (t, a) => t += a); Console.WriteLine($"Баланс: {totalBalanceAmount}"); }
public decimal ConvertCurrency(decimal value, string currencyFrom, string currencyTo) { decimal result = 0; try { result = converter.ConvertCurrency(value, currencyFrom, currencyTo); logger.SaveGetCurrencyLog(value, result, currencyFrom, currencyTo); } catch (Exception ex) { logger.SaveErrorLog(ex, "ConvertCurrency"); throw; } return(result); }
public static decimal ToCurrency(this string currencyValue, ICurrencyConverter converter, string fromCurrencySymbol = "TL", string toCurrencySymbol = "TL") { var returnVal = default(decimal); //fromCurrencySymbol ve toCurrencySymbol aynı ise //var currencySymbols = new string[] { "TRY", "TL", "YTL" }; //if ((currencySymbols.Contains(fromCurrencySymbol) && currencySymbols.Contains(toCurrencySymbol)) || (fromCurrencySymbol==toCurrencySymbol)) //{ // return floatValue; //} var logger = LoggerService.GetLogger(ConstantHelper.Logging.Log2DbCategoryName); Let.Logger = () => logger; returnVal = Let.Us. TrapLog((exp) => { var logItem = new LogItem { Title = "Kur dönüşümü yapılamadı !!!", Message = string.Format( "converter:{0} - currencyValue:{1} - fromCurrencySymbol:{2} - toCurrencySymbol:{3}", converter.GetType().FullName, currencyValue, fromCurrencySymbol, toCurrencySymbol), Exception = exp }; logger.Log(logItem); }). //TODO:Resource'tan al MustBeNonDefault(currencyValue, fromCurrencySymbol, toCurrencySymbol). MustBeNonNull(converter). Return(() => { var stringValue = currencyValue.ToStringCultureSeparatorFormat(cultureInfo: CultureInfo.CurrentCulture); var floatValue = stringValue.To <decimal>(provider: CultureInfo.CurrentCulture, returnDefaultValue: true); //TODO: Test et var returnCurrencyValue = converter.ConvertCurrency(floatValue, fromCurrencySymbol, toCurrencySymbol); return(returnCurrencyValue); }); return(returnVal); }