Exemplo n.º 1
0
        public async Task <IActionResult> GetLastRatesAsync()
        {
            var lastRates = await _ratesRepository.GetLastRatesAsync();

            //Currencies currencies = new Currencies();
            //currencies.CurrencyOfMetal = currencyOfMetal;
            //currencies.CurrencyOfValute = currencyOfValute;
            //Dictionary<string, double> valuteCurrencies, metalCurrencies;

            //Dictionary<string, double> rates = JsonConvert.DeserializeObject<Dictionary<string, double>>(lastRates.ToString());

            //metalCurrencies = rates.Take(4)
            //    .ToDictionary(x => x.Key, x => x.Value);
            //valuteCurrencies = rates.Skip(5)
            //.ToDictionary(x => x.Key, x => x.Value);

            //if ((!valuteCurrencies.ContainsKey(currencyOfValute) && currencyOfValute != "USD") ||
            //    (!valuteCurrencies.ContainsKey(currencyOfMetal) && currencyOfMetal != "USD"))
            //{
            //    return BadRequest("You entered a currency of an unknown type");
            //}

            //double selectedValuteCurrency = 0;
            //double selectedMetalCurrency = 0;

            //foreach (KeyValuePair<string, double> valuteCurrency in valuteCurrencies)
            //{
            //    if (selectedMetalCurrency != 0 && selectedValuteCurrency != 0) break;
            //    else if (currencyOfMetal == "USD" && selectedValuteCurrency != 0) break;
            //    else if (currencyOfValute == "USD" && selectedMetalCurrency != 0) break;
            //    else if (currencyOfValute == "USD" && currencyOfMetal == "USD") break;

            //    if (valuteCurrency.Key == currencyOfMetal)
            //    {
            //        selectedMetalCurrency = valuteCurrency.Value;
            //    }
            //    if (valuteCurrency.Key == currencyOfValute)
            //    {
            //        selectedValuteCurrency = valuteCurrency.Value;
            //    }
            //}

            //if (currencyOfMetal != "USD")
            //{
            //    foreach (KeyValuePair<string, double> metalCurrency in metalCurrencies)
            //    {
            //        currencies.Rates.Add(metalCurrency.Key, Math.Round(metalCurrency.Value * selectedMetalCurrency, 5));
            //    }
            //}
            //else
            //{
            //    currencies.Rates = metalCurrencies;
            //}

            //if (currencyOfValute != "USD")
            //{
            //    foreach (KeyValuePair<string, double> valuteCurrency in valuteCurrencies)
            //    {
            //        if (valuteCurrency.Key == currencyOfValute)
            //        {
            //            currencies.Rates.Add("USD", valuteCurrency.Value);
            //        }
            //        currencies.Rates.Add(valuteCurrency.Key, Math.Round(selectedValuteCurrency / valuteCurrency.Value, 5));
            //    }
            //}
            //else
            //{
            //    if (!valuteCurrencies.ContainsKey("USD"))
            //    {
            //        currencies.Rates.Add("USD", 1);
            //    }

            //    foreach (KeyValuePair<string, double> valuteCurrency in valuteCurrencies)
            //    {
            //        currencies.Rates.Add(valuteCurrency.Key, valuteCurrency.Value);
            //    }
            //}

            return(Ok(lastRates));
        }