예제 #1
0
        protected override async Task <GetLatestCryptoCurrencyQuotesResponse> Run(GetLatestCryptoCurrencyQuotes request,
                                                                                  CancellationToken cancellationToken)
        {
            var result         = new GetLatestCryptoCurrencyQuotesResponse();
            var cryptoCurrency = await _cryptoRepository.GetById(request.Id);

            if (cryptoCurrency == null)
            {
                throw new Exception("Crypto Currency was not found");
            }

            result.Entity = new GetLatestCryptoCurrencyQuotesItem
            {
                Id = cryptoCurrency.Id
            };

            var latestQuote = await GetLatestCryptoCurrencyQuote(cryptoCurrency);

            var currencies = await _currencyRepository.GetAll();

            var rates = await _exchangeRateService.GetLatestExchangeRates();

            result.Entity.Quotes = currencies.Select(ConvertCurrencyToDto(rates, latestQuote)).ToList();

            return(result);
        }