コード例 #1
0
        public async Task <IActionResult> GetAllProducts([FromQuery] string requestedCurrency, string requestedProduct)
        {
            var            parser = new DataParser();
            ConverterLogic logic  = new ConverterLogic();

            string currencyData = await parser.GetFile(RateUrl, client);

            string productData = await parser.GetFile(ProductUrl, client);

            List <CurrencyRate> RateList    = logic.CurrencyRateToList(currencyData, ',', 1);
            List <Product>      ProductList = logic.ProductsToList(productData, ',', 1);

            Result price = logic.ConvertCurrency(RateList, ProductList, requestedCurrency, requestedProduct);

            var output = JsonConvert.SerializeObject(price);

            return(Ok(output));
        }
        public async Task <IActionResult> GetAllItemsSortedAsync([FromQuery] string targetCurrency, string product)
        {
            var            parser = new DataParser();
            ConverterLogic logic  = new ConverterLogic();

            targetCurrency = targetCurrency.ToUpper();
            string exchangeData = await parser.GetFileAsync(exchangeUrl, HttpClient);

            string productData = await parser.GetFileAsync(productUrl, HttpClient);

            List <ExchangeRate> exchangeRates = parser.ExchangeRateToList(exchangeData, ',', 1);
            List <Product>      products      = parser.ProductsToList(productData, ',', 1);

            Price price = logic.ConvertCurrency(exchangeRates, products, targetCurrency, product);

            var output = JsonConvert.SerializeObject(price);

            return(Ok(output));
        }