/// <summary> /// Get currency information /// </summary> /// <param name="currencyCollectionModel"><see cref="CurrencyCollectionRequest"/></param> /// <returns>returns collection of <see cref="CurrencyResultResponse"/> items</returns> public async Task <IEnumerable <CurrencyResultResponse> > GetCurrencyResultsAsync(CurrencyCollectionRequest currencyCollectionModel) { var currencyResult = new List <CurrencyResultResponse>(); var currencyModel = new CurrencyModel(); _dateChecker.ValidateDate(currencyCollectionModel.StartDate, currencyCollectionModel.EndDate); (DateTime StartDate, DateTime EndDate)dateItems = _dateChecker.SetCorrectDate(currencyCollectionModel.StartDate, currencyCollectionModel.EndDate); currencyModel.StartDate = dateItems.StartDate; currencyModel.EndDate = dateItems.EndDate; foreach (KeyValuePair <string, string> currencyCode in currencyCollectionModel.CurrencyCodes) { currencyModel.CurrencyBeingMeasured = currencyCode.Key; currencyModel.CurrencyMatched = currencyCode.Value; List <CurrencyResultResponse> currencyResults = _cacheDatabase.GetAsync(currencyModel).Select(c => new CurrencyResultResponse { CurrencyBeingMeasured = c.Currency.CurrencyBeingMeasured, CurrencyMatched = c.Currency.CurrencyMatched, CurrencyValue = c.Value, DailyDataOfCurrency = c.DailyDataOfCurrency }).ToList(); if (currencyResults.Count == 0) { var xmlBody = await _currencyGetterService.FetchDataAsync(currencyModel); currencyResults = _xmlReader.GetCurrencyResults(currencyModel, xmlBody).ToList(); foreach (CurrencyResultResponse c in currencyResults) { await _cacheDatabase.SaveAsync(c); } } currencyResult.AddRange(currencyResults); } return(currencyResult); }