예제 #1
0
        private async Task AddUkprnToProviderCache(long ukprn)
        {
            var cacheItem = await ukprnCache.TryGet(CacheKeys.ProvidersKey, CancellationToken.None);

            var ukprnList = cacheItem.HasValue ? cacheItem.Value : new List <long>();

            if (!ukprnList.Contains(ukprn))
            {
                ukprnList.Add(ukprn);
            }
            await ukprnCache.AddOrReplace(CacheKeys.ProvidersKey, ukprnList, CancellationToken.None);
        }
예제 #2
0
        public async Task ProcessApprenticeshipUpdate(ApprenticeshipUpdated updatedApprenticeship)
        {
            logger.LogDebug(
                $"Getting apprenticeships cache item using uln for apprenticeship id: {updatedApprenticeship.Id}");
            var cacheItem = await dataCache.TryGet(updatedApprenticeship.Uln.ToString(), CancellationToken.None);

            logger.LogDebug(cacheItem.HasValue
                ? "Item found in the cache."
                : "No cache item found. Will now create new apprenticeships list.");
            var apprenticeships = cacheItem.HasValue ? cacheItem.Value : new List <ApprenticeshipModel>();

            logger.LogDebug("Removing old version of the apprenticeship.");
            apprenticeships.RemoveAll(apprenticeship => apprenticeship.Id == updatedApprenticeship.Id);
            logger.LogDebug("Now mapping the ApprenticeshipUpdated event to the ApprenticeshipModel.");
            var model = mapper.Map <ApprenticeshipModel>(updatedApprenticeship);

            logger.LogDebug("Finished mapping the apprenticeship model, now adding to the cache.");
            apprenticeships.Add(model);
            await dataCache.AddOrReplace(model.Uln.ToString(), apprenticeships, CancellationToken.None);

            logger.LogInfo(
                $"Finished storing the apprenticeship details in the cache. Apprenticeship id: {model.Id}, Account: {model.AccountId}, Provider: {model.Ukprn}");
            await AddUkprnToProviderCache(updatedApprenticeship.Ukprn);
        }