private List <ExrByDay> AddAdditionalExchangeRatesByDay(List <ExchangeRate> exchangeRates, List <ExrByDay> exrByDay) { var availableDates = new List <DateTime>(); foreach (var exr in exchangeRates) { availableDates.Add(exr.Date); } availableDates = availableDates.Distinct().ToList(); foreach (var date in availableDates) { var item = new ExrByDay() { DateTime = date, Base = "EUR", CurrencyRates = new List <CurrencyRate>() }; foreach (var exr in exchangeRates.Where(x => x.Date == date)) { var rate = new CurrencyRate() { CurrencyCode = exr.SourceCurrency, Rate = exr.Factor, }; item.CurrencyRates.Add(rate); } if (item.CurrencyRates.Count > 0) { exrByDay.Add(item); } } return(exrByDay); }
private List <ExrByDay> FilteredExchangeRatesByDay(List <string> requiredCodes, List <ExchangeRate> exchangeRates, DateTime startDate, DateTime endDate) { var list = new List <ExrByDay>(); for (DateTime date = startDate; date.Date <= endDate; date = date.AddDays(1)) { var item = new ExrByDay() { DateTime = date, Base = "EUR", CurrencyRates = new List <CurrencyRate>() }; foreach (var exr in exchangeRates.Where(x => x.Date == date && requiredCodes.Contains(x.SourceCurrency))) { var rate = new CurrencyRate() { CurrencyCode = exr.SourceCurrency, Rate = exr.Factor, }; item.CurrencyRates.Add(rate); } if (item.CurrencyRates.Count > 0) { list.Add(item); } } return(list); }