Exemple #1
0
        public async Task <IHttpActionResult> UpdateAsync(int id, ExchangeRateDto exchangeRate)
        {
            var exchangeRateInDb = await _exchangeRateRepository.GetAsync(id);

            if (exchangeRateInDb == null)
            {
                return(NotFound());
            }

            _exchangeRateRepository.Add(exchangeRate.Map <ExchangeRate>());
            await UnitOfWork.CompleteAsync();

            return(Ok());
        }
        public async Task AddExchangeRatesFor(string [] currencies)
        {
            var httpResponseMessage = await _exchangeRateClient.GetExchangeRatesFor(BaseCurrencySymbol, string.Join(',', currencies));

            if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var content = httpResponseMessage.Content;
                var currencyExchangeRates = await content.ReadAsAsync <OpenExchangeRates>();

                foreach (var rate in currencyExchangeRates.Rates)
                {
                    _exchangeRateRepository.Add(new ExchangeRate(BaseCurrencySymbol, rate.Key, rate.Value, DateTime.Now));
                }
            }
            else
            {
                Console.WriteLine($"Cannot get exchange rates for USD to currencies: {string.Join(',', currencies)}, StatusCode: {httpResponseMessage.StatusCode}, Reason: {httpResponseMessage.ReasonPhrase}");
            }
        }