Пример #1
0
        public async Task ScrapShowsAsync()
        {
            var lastShowId = await _repo.GetLastShowId();

            var pageToLoad = GetPageNumber(lastShowId + 1);

            var showsToLoadExist = true;

            while (showsToLoadExist)
            {
                var shows = await _apiClient.GetShowsAsync(pageToLoad);

                if (shows.Count > 0)
                {
                    pageToLoad += 1;
                    _logger.LogInformation($"Starting insert page {pageToLoad} at {DateTime.Now.ToLongTimeString()}");
                    await _repo.AddShowsAsync(shows);

                    _logger.LogInformation($"End insert page {pageToLoad} at {DateTime.Now.ToLongTimeString()}");
                }
                else
                {
                    showsToLoadExist = false;
                }
            }
        }
        public async Task <bool> AddShowsAsync(IEnumerable <ShowModel> showModels)
        {
            try
            {
                var shows = _mapper.Map <IEnumerable <Show> >(showModels);

                await _showRepository.AddShowsAsync(shows);
            }
            catch (DatabaseException exception)
            {
                _logger.LogError(exception, _strings[StringsEnum.DATABASE_ERROR_SAMPLE]);
                return(false);
            }

            return(true);
        }