private CurrencyInfoDto CreateCurrencyInfo( string id, IReadOnlyDictionary <string, CurrencyDataModel> currencyMap) { if (!currencyMap.TryGetValue(id, out var currency)) { throw new NotSupportedException(); } var currencyInfo = new CurrencyInfoDto { Id = currency.Id, CharCode = currency.CharCode, NumCode = currency.NumCode, Name = currency.Name }; var currentUnitValue = currency.GetUnitValue(); var currencyCourseList = new List <CurrencyCourseDto>(); foreach (var currencyToCalculateId in _currencyToCalculateIdList) { if (!currencyMap.TryGetValue(currencyToCalculateId, out var currencyToCalculate)) { throw new NotSupportedException(); } var currencyToCalculateUnitValue = currencyToCalculate.GetUnitValue(); var currencyCourse = new CurrencyCourseDto { Id = currencyToCalculate.Id, CharCode = currencyToCalculate.CharCode, UnitValue = currentUnitValue / currencyToCalculateUnitValue }; currencyCourseList.Add(currencyCourse); } currencyInfo.Courses = currencyCourseList.ToArray(); return(currencyInfo); }
public async Task <CurrencyInfoDto> GetInvestmentCurrencyAsync(int investmentWalletId) { var investmentWallet = await this.dbContext.InvestmentWallets .Include(iw => iw.Currency) .FirstOrDefaultAsync(iw => iw.Id == investmentWalletId); if (investmentWallet == null) { throw new ArgumentException(GlobalConstants.InvestmentWalletNotExist); } var currency = new CurrencyInfoDto() { CurrencyId = investmentWallet.CurrencyId, Code = investmentWallet.Currency.Code, Name = investmentWallet.Currency.Name, }; return(currency); }