Ejemplo n.º 1
0
        public async Task <IActionResult> GetCalculatedExchangeForCurrencies(int amount, string fromCurrency, string toCurrency)
        {
            var    uriString = _apiConnections.UriString;
            string dataFromCurrency;
            string dataToCurrency;

            try
            {
                dataFromCurrency = await _exchange.GetExchangeRatesData(uriString, _apiConnections.RequestUriToSingleRate(fromCurrency));

                dataToCurrency = await _exchange.GetExchangeRatesData(uriString, _apiConnections.RequestUriToSingleRate(toCurrency));
            }
            catch (StatusCodeException e)
            {
                var codeNumber = e.CodeNumber;
                return(StatusCode(codeNumber, StatusCodeResponses.GetResponseMessage(codeNumber)));
            }
            var currencyFrom = _currencyDao.GetCurrency(fromCurrency.ToUpper(), _context, _codesForExchangeRates);
            var currencyTo   = _currencyDao.GetCurrency(toCurrency.ToUpper(), _context, _codesForExchangeRates);

            var conversions = _exchange.GetConversionsDetails(dataFromCurrency, dataToCurrency, amount, currencyFrom, currencyTo);
            await _conversionDao.AddConversions(conversions, _context);

            var actualConversion = $"{amount}{fromCurrency.ToUpper()}:{conversions.Result}{toCurrency.ToUpper()}";
            var currency         = JsonConvert.SerializeObject(actualConversion);

            return(Ok(currency));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>CurrencyResponse.</returns>
        public CurrencyResponse GetCurrencies(CurrencyRequest request)
        {
            var response = new CurrencyResponse();

            if (request.LoadOptions.Contains("Currencies"))
            {
                if (request.LoadOptions.Contains("IsActive"))
                {
                    response.Currencies = CurrencyDao.GetCurrenciesByActive();
                }
                else
                {
                    response.Currencies = request.LoadOptions.Contains("CurrenciesIsMain") ? CurrencyDao.GetCurrenciesByIsMain() : CurrencyDao.GetCurrencies();
                }
            }
            if (request.LoadOptions.Contains("Currency"))
            {
                response.Currency = request.LoadOptions.Contains("CurrencyCode") ? CurrencyDao.GetCurrenciesByCurrencyCode(request.CurrencyCode) : CurrencyDao.GetCurrency(request.CurrencyId);
            }

            return(response);
        }
 /// <summary>
 /// Gets the account category by identifier.
 /// </summary>
 /// <param name="currencyId">The account currency identifier.</param>
 /// <returns>AccountCategoryEntity.</returns>
 public CurrencyEntity GetCurrencyById(string currencyId)
 {
     return(ICurrencyDao.GetCurrency(currencyId));
 }