/// <summary> /// This method is to retrieve ExchangeRatesData from APIResponse and insert to DB /// </summary> /// <param name="CurrencyMasterID"></param> /// <param name="aPIResponse"></param> /// <returns></returns> public async Task <long> InsertExchangeRates(long CurrencyMasterID, APIResponse aPIResponse) { try { List <ExchangeRatesData> listOfExchanges = new List <ExchangeRatesData>(); foreach (KeyValuePair <string, string> keyValuePair in aPIResponse.rates) { ExchangeRatesData exchangeRates = new ExchangeRatesData(); exchangeRates.CurrencyMasterID = CurrencyMasterID; exchangeRates.BaseCurrency = aPIResponse.@base; exchangeRates.ConvertedCurrency = keyValuePair.Key; double exchangeRate = _calculationHelper.CheckIfDouble(keyValuePair.Value); exchangeRates.ExchangeRate = (exchangeRate != double.NaN) ? exchangeRate : 0; exchangeRates.UpdatedDate = DateTime.Now; listOfExchanges.Add(exchangeRates); } await _exchangeRatesService.AddExchangeRatesAsync(listOfExchanges); return(1); } catch (Exception ex) { _logger.LogError("Error while inserting data in exchangeRates table as: " + ex.Message); return(0); } }
private void OnCallBack() { _timer.Dispose(); ExchangeRatesData.UpdateCurrencyRate(); if (!IsInit) { Application.Current.Dispatcher.Invoke(() => { IsInit = true; ComboBoxCurrenciesL.ItemsSource = ExchangeRatesData.ExchangeRates; ComboBoxCurrenciesL.SelectedIndex = ExchangeRatesData.ExchangeRates.IndexOf( ExchangeRatesData.ExchangeRates.Single(p => p.@base == "EUR")); ComboBoxCurrenciesL.SelectionChanged += CalculateL; AmountL.TextChanged += CalculateL; ComboBoxCurrenciesR.ItemsSource = ExchangeRatesData.ExchangeRates .ElementAt(ComboBoxCurrenciesL.SelectedIndex).rates.Keys; ComboBoxCurrenciesR.SelectedIndex = ExchangeRatesData.ExchangeRates.IndexOf( ExchangeRatesData.ExchangeRates.Single(p => p.@base == "USD")); ComboBoxCurrenciesR.SelectionChanged += CalculateR; AmountR.TextChanged += CalculateR; AmountL.Text = "1000"; }); } _timer = new Timer(_ => OnCallBack(), null, 1000 * 2, Timeout.Infinite); //in 10 seconds }
public Dictionary <string, string> GetExchangeRatesByTimeFrame(DateTime startDate, DateTime endDate, string currency) { List <CurrencyMaster> listOfdays = currencyExchangeDBContext.CurrencyMasters .Where(a => a.ApplicableOn >= startDate && a.ApplicableOn <= endDate).ToList(); Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); foreach (CurrencyMaster curMstr in listOfdays) { ExchangeRatesData exchangeRatesData = currencyExchangeDBContext.exchangeRates .Where(a => a.CurrencyMasterID == curMstr.Id && a.ConvertedCurrency == currency).FirstOrDefault(); keyValuePairs.Add(curMstr.ApplicableOn.ToString("yyyy-MM-dd"), Math.Round(exchangeRatesData.ExchangeRate, 1).ToString()); } return(keyValuePairs); }