Exemplo n.º 1
0
        public async Task <IEnumerable <Domain.Models.TcgCard> > GetMTGCardListAsync(string set)
        {
            var cachedCards = await _cardCachingService.GetCachedCardsIfPresentAsync(set);

            if (cachedCards != null)
            {
                return(cachedCards);
            }
            else
            {
                var cardList  = new List <MtgCard>();
                var cardCount = 100;
                var page      = 0;

                while (cardCount > 50)
                {
                    var restRequest   = new RestRequest("cards").AddParameter("set", set).AddParameter("page", ++page);
                    var requestResult = await _restClient.GetAsync <MtgCards>(restRequest).ConfigureAwait(false);

                    cardCount = requestResult.Cards != null ? requestResult.Cards.Count : 0;

                    if (cardCount > 0)
                    {
                        cardList.AddRange(requestResult.Cards);
                    }
                }

                var mappedCardList = MtgMapper.MapCardList(cardList);

                _cardCachingService.AddToCache(mappedCardList);

                return(mappedCardList);
            }
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Domain.Models.TcgSet> > GetSetlistAsync()
        {
            var restRequest = new RestRequest("sets");

            var result = await _restClient.GetAsync <MtgSets>(restRequest).ConfigureAwait(false);

            return(MtgMapper.MapSetLists(result.Sets));
        }