public async Task <SyncMetadataCommandResult> Handle(SyncMetadataCommand request, CancellationToken cancellationToken) { var isSyncCompleted = false; while (!isSyncCompleted) { var lastSyncId = await _showsRepository.GetMaxExternalIdAsync(); _logger.LogInformation($"Last synced show id: {lastSyncId}"); var shows = await _service.ScrapeBatchAsync(lastSyncId, request.SyncBatchSize); foreach (var show in shows) { var model = await _showsRepository.FindByExternalIdAsync(show.Id); // Apparently this show has been synced already - let's skip it if (model != null) { continue; } model = await MapToDomainModel(show); await _showsRepository.AddAsync(model); } isSyncCompleted = !shows.Any(); } return(SyncMetadataCommandResult.Success()); }
public async Task <Show> AddAsync(Show show) { try { if (await _showsRepository.AddAsync(show) > 0) { return(show); } } catch (Exception ex) { Console.WriteLine(ex); } return(null); }