Exemple #1
0
        public async Task <FeProvider> RetrieveAsync(int ukprn, CancellationToken cancellationToken)
        {
            if (ukprn < 10000000 || ukprn > 99999999)
            {
                throw new InvalidRequestException("UKPRN must be an 8 digit number");
            }

            var provider = await _feProviderRepository.RetrieveProviderAsync(ukprn, cancellationToken);

            return(provider);
        }
Exemple #2
0
        public async Task <Guid> UpsertLearner(Learner learner, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(learner.LearnRefNumber))
            {
                throw new InvalidRequestException("Must provide LearnRefNumber");
            }

            var provider = await _providerRepository.RetrieveProviderAsync(learner.Ukprn, cancellationToken);

            if (provider == null)
            {
                throw new InvalidRequestException($"Cannot find provider with UKPRN {learner.Ukprn}");
            }

            var upsertResult = await _learnerRepository.UpsertLearnerAsync(learner, cancellationToken);

            _logger.LogInformation("Upsert learner {UKPRN} / {LearnRefNumber} resulted in the learner being {UpsertAction}, id: {LearnerId}",
                                   learner.Ukprn, learner.LearnRefNumber, upsertResult.Created ? "CREATED" : "UPDATED", upsertResult.Key);
            return(upsertResult.Key);
        }