Beispiel #1
0
        private async void LoadExchangeRateList()
        {
            if (isExchangeRateListLoaded)
            {
                return;
            }

            if (queryDispatcher == null)
            {
                return;
            }

            List <ExchangeRateModel> exchangeRates = await queryDispatcher.QueryAsync(new ListTargetCurrencyExchangeRates(UniqueCode));

            if (exchangeRates == null)
            {
                return;
            }

            ExchangeRates.AddRange(exchangeRates);
            ExchangeRates.SortDescending(e => e.ValidFrom);
            RaisePropertyChanged(nameof(ExchangeRates));

            isExchangeRateListLoaded = true;
        }
Beispiel #2
0
        public ExchangeRates GetExchangeRates(ReqEmpty req)
        {
            ExchangeRates rates = HttpContext.Current.Application["exchangeRates"] as ExchangeRates;

            if (rates == null || rates.Date < Provider.Database.Now.Date)
            {
                rates = new ExchangeRates {
                    Date = Provider.Database.Now.Date
                };

                List <ExchangeRate> list =
                    Provider.Database.ReadList <ExchangeRate>("select * from ExchangeRate where InsertDate>={0}",
                                                              Provider.Database.Now.Date);
                if (list == null || list.Count == 0)
                {
                    XmlTextReader rdr = new XmlTextReader("http://www.tcmb.gov.tr/kurlar/today.xml");
                    DataSet       ds  = new DataSet();
                    ds.ReadXml(rdr);

                    foreach (DataRow dr in ds.Tables["Currency"].Rows)
                    {
                        try
                        {
                            ExchangeRate rate = new ExchangeRate
                            {
                                Currency =
                                    (dr["CurrencyCode"].ToString() == "USD")
                                            ? "$"
                                            : (dr["CurrencyCode"].ToString() == "EUR" ? "€" : dr["CurrencyCode"].ToString()),
                                PriceTL =
                                    Convert.ToInt32(
                                        decimal.Parse(dr["ForexSelling"].ToString(), CultureInfo.InvariantCulture) *
                                        1000000 / int.Parse(dr["Unit"].ToString()))
                            };
                            rate.Save();

                            rates.Add(rate.ToEntityInfo <ExchangeRateInfo>());
                        }
                        catch { }
                    }

                    HttpContext.Current.Application["exchangeRates"] = rates;
                }
                else
                {
                    rates.Date = Provider.Database.Now.Date;
                    rates.AddRange(list.ToEntityInfo <ExchangeRateInfo>());
                    HttpContext.Current.Application["exchangeRates"] = rates;
                }
            }

            return(rates);
        }