Exemple #1
0
        private async void LoadCurrencyRatesAsync()
        {
            CurrencyRates.Clear();
            var newCurrencyRates = await currencyRateRepository.GetCurrencyRates();

            if (newCurrencyRates != null)
            {
                foreach (var code in newCurrencyRates)
                {
                    CurrencyRates.Add(code);
                }

                SelectedRateFirst  = CurrencyRates[0];
                SelectedRateSecond = CurrencyRates[1];
            }
        }
        private async void Update()
        {
            try
            {
                UpdateVisibility = Visibility.Visible;
                var data = await UpdateRates();

                data.Add(new CurrencyRate
                {
                    CurrencyCode  = "HUF",
                    Unit          = 1,
                    ValueInForint = 1
                });
                CurrencyRates.Clear();
                CurrencyRates.AddRange(data.OrderBy(d => d.CurrencyCode));
                OnPropertyChanged(() => CurrencyRates);

                var types = from rate in CurrencyRates
                            orderby rate.CurrencyCode ascending
                            select rate.CurrencyCode;
                CurrencyTypes.Clear();
                CurrencyTypes.AddRange(types);
                OnPropertyChanged(() => CurrencyTypes);
                _selectedInputIndex  = CurrencyTypes.IndexOf("EUR");
                _selectedOutputIndex = CurrencyTypes.IndexOf("HUF");
                OnPropertyChanged(() => SelectedInputIndex);
                OnPropertyChanged(() => SelectedOutputIndex);
                LastUpdate       = DateTime.Now;
                Input            = 1;
                UpdateVisibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                LastUpdate = DateTime.Now;
                CurrencyRates.Clear();
                CurrencyTypes.Clear();
                _app.Log.Exception(ex);
                await _app.ShowMessageBox("Error", "Error calling webservice", DialogButtons.Ok);

                UpdateVisibility = Visibility.Collapsed;
            }
        }