private async Task <IEnumerable <Rate> > ConvertResponseToList(RatesResponse response) { var currenciesMap = (await _ratesRepository.GetAllCurrencyAsync()).ToDictionary(key => key.Code, value => value); var results = response.RatesDictionary.Select(x => x.Value.Select(y => new Rate { BaseCurrencyId = currenciesMap[response.BaseCurrencyCode].Id, BaseCurrency = currenciesMap[response.BaseCurrencyCode], ResultCurrencyId = currenciesMap[y.Key].Id, ResultCurrency = currenciesMap[y.Key], RateDate = DateTime.Parse(x.Key), RateValue = y.Value })); var resultingRates = new List <Rate>(); foreach (var result in results) { resultingRates.AddRange(result); } return(resultingRates); }