Пример #1
0
        public async Task <IActionResult> GetExchange(string currency)
        {
            if (_context.ValidateCurrency(currency))
            {
                HttpResponseMessage response = await http.GetAsync("https://www.bancoprovincia.com.ar/Principal/dolar");

                response.EnsureSuccessStatusCode();
                string body = await response.Content.ReadAsStringAsync();

                var res = JsonSerializer.Deserialize <string[]>(body);
                if (currency == "BRL")
                {
                    res[0] = (double.Parse(res[0]) * .25).ToString();
                    res[1] = (double.Parse(res[1]) * .25).ToString();
                }
                return(Ok(res));
            }
            else
            {
                return(NotFound("Currency not found!"));
            }
        }