Esempio n. 1
0
        public async Task <ActionResult> Index()
        {
            var result = await _exchangeService.CurrenciesAsync(default(DateTime), default(DateTime));

            ViewData["cookie"] = "kursy";

            //var listaa = new Dictionary<string, string>();
            //foreach (var item in result.Result)
            //{
            //    foreach (var res in item.rates)
            //    {
            //        listaa.Add(res.code, res.currency);
            //    }
            //}
            //foreach (var item in listaa)
            //{
            //    Debug.WriteLine($"<option value=\"{item.Key}\">{item.Value} ({item.Key})</option>");
            //}

            return(View(result));
        }
        public async Task <ResultModel <CalculateValute> > ExchangeRateAsync(CalculateValute calculateValute)
        {
            var actualyCurrency = await _exchangeRateService.CurrenciesAsync(default(DateTime), default(DateTime));

            var targetCurrencyList = actualyCurrency.Result.ToList();
            var targetCurrency     = targetCurrencyList[0].rates;

            calculateValute.targetcurrency = targetCurrency.Where(a => a.code == calculateValute.targetcurrencycode)
                                             .Select(a => a.mid).First();
            calculateValute.basiccurrency = targetCurrency.Where(a => a.code == calculateValute.basiccurrencycode)
                                            .Select(a => a.mid).First();

            calculateValute.value = (calculateValute.basiccurrency * calculateValute.basiccurrencyinput) / calculateValute.targetcurrency;

            return(new ResultModel <CalculateValute>()
            {
                Code = 200,
                Message = null,
                Result = calculateValute
            });
        }