Esempio n. 1
0
        public async Task <IActionResult> CalculateAmount(long amount, string firstCurrency, string secondCurrency)

        {
            _repository.AddNewInternalRequest(GetRequestUrl());
            if (!(_repository.CurrencyExists(firstCurrency) && _repository.CurrencyExists(secondCurrency)))
            {
                return(NotFound());
            }

            if (amount < 0)
            {
                return(BadRequest());
            }

            try
            {
                var firstCurrencyDetails = await _apiClient.GetCurrencyCourse(firstCurrency);

                _repository.AddNewExternalRequest(ApplicationHelper.GetApiClientURL(firstCurrency));
                var secondCurrencyDetails = await _apiClient.GetCurrencyCourse(secondCurrency);

                _repository.AddNewExternalRequest(ApplicationHelper.GetApiClientURL(secondCurrency));

                Calculation calculation = ApplicationHelper.GetCalculation(amount, firstCurrencyDetails, secondCurrencyDetails);
                return(Ok(calculation));
            }
            catch (System.Exception)
            {
                return(StatusCode(500));
            }
        }