Beispiel #1
0
        static async Task StoreEstablishments(Establishment[] establishments, CancellationToken cancellationToken)
        {
            for (var i = 0; i < establishments.Length; i++)
            {
                _logger.Info($"Storing establishment {i} of {establishments.Length}: {establishments[i].Urn}");
                var pointInTimeEstablishment = Clone <PointInTimeEstablishment>(establishments[i]);
                pointInTimeEstablishment.PointInTime = DateTime.UtcNow.Date;

                await _establishmentRepository.StoreAsync(pointInTimeEstablishment, cancellationToken);
            }
        }
Beispiel #2
0
        private async Task StoreEstablishmentAndRaiseEventAsync(
            PointInTimeEstablishment staging,
            bool isUpdate,
            CancellationToken cancellationToken)
        {
            var current = await _establishmentRepository.GetEstablishmentAsync(staging.Urn, cancellationToken);

            staging.IsCurrent = current == null || staging.PointInTime > current.PointInTime;
            if (current != null && staging.IsCurrent)
            {
                current.IsCurrent = false;
            }

            var toStore = current == null || current.IsCurrent
                ? new[] { staging }
                : new[] { current, staging };

            await _establishmentRepository.StoreAsync(toStore, cancellationToken);

            _logger.Debug($"Stored establishment {staging.Urn} in repository");

            var learningProvider = await _mapper.MapAsync <LearningProvider>(staging, cancellationToken);

            learningProvider._Lineage = null;

            if (isUpdate)
            {
                await _eventPublisher.PublishLearningProviderUpdatedAsync(learningProvider, staging.PointInTime, cancellationToken);
            }
            else
            {
                await _eventPublisher.PublishLearningProviderCreatedAsync(learningProvider, staging.PointInTime, cancellationToken);
            }

            _logger.Debug($"Sent event for establishment {staging.Urn}");
        }