Beispiel #1
0
        public async Task <string> GetRateAsync(string selectedBase, string selectedQuote, DateTime date)
        {
            if (selectedBase == selectedQuote)
            {
                return("1");
            }
            else
            {
                string baseCurrency;
                string quoteCurrency;
                try
                {
                    baseCurrency  = new string((selectedBase.ToString().Substring(selectedBase.Length - 4, 3).ToArray()));
                    quoteCurrency = new string((selectedQuote.Substring(selectedQuote.Length - 4, 3).ToArray()));
                }
                catch
                {
                    throw new Exception("Invalid currencies names");
                }
                var model = await _apiHelper.GetRateFromAPIAsync(baseCurrency, quoteCurrency, date.ToString("yyyy-MM-dd"));

                var info = new NumberFormatInfo();
                info.NumberDecimalSeparator = ".";

                return((model.Rates.First().Value).ToString(info));
            }
        }
Beispiel #2
0
        public async Task <decimal> GetRateAsync(string selectedBase, string selectedQuote, DateTime date)
        {
            string baseCurrency;
            string quoteCurrency;

            try
            {
                baseCurrency  = new string((selectedBase.ToString().Substring(selectedBase.Length - 4, 3).ToArray()));
                quoteCurrency = new string((selectedQuote.Substring(selectedQuote.Length - 4, 3).ToArray()));
            }
            catch
            {
                throw new Exception("Invalid currencies names");
            }
            var model = await _apiHelper.GetRateFromAPIAsync(baseCurrency, quoteCurrency, date.ToString("yyyy-MM-dd"));

            return(model.Rates.First().Value);
        }