private async Task <IEnumerable <ProviderUser> > GetProvider(long ukprn) { var users = await _emailService.GetUsersAsync(ukprn); if (users == null) { _logger.Warn($"Can't find and user for provider {ukprn}."); return(new List <ProviderUser>()); } var accountUserResult = (await _retryPolicy.ExecuteAndCaptureAsync(() => _providerAccountClient.GetAccountUsers(ukprn))); var accountUser = accountUserResult.Result?.ToArray(); foreach (var user in users) { var u = accountUser ?.FirstOrDefault(m => user.Email.Trim().ToLower() == m.EmailAddress.Trim() ?.ToLower()); user.ReceiveNotifications = u == null || u.ReceiveNotifications; user.Ukprn = ukprn; } return(users); }
protected override async Task HandleCore(TriageDataLockCommand message) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var dataLock = await _dataLockRepository.GetDataLock(message.DataLockEventId); AssertDataLockBelongsToApprenticeship(message.ApprenticeshipId, dataLock); var triageStatus = (TriageStatus)message.TriageStatus; if (dataLock.TriageStatus == triageStatus) { _logger.Warn($"Trying to update data lock for apprenticeship: {message.ApprenticeshipId} with the same TriageStatus ({message.TriageStatus}) "); return; } AssertValidTriageStatus(triageStatus, dataLock); await AssertNoPendingApprenticeshipUpdate(dataLock, message.ApprenticeshipId); await _dataLockRepository.UpdateDataLockTriageStatus(message.DataLockEventId, triageStatus); }
private Polly.Retry.RetryPolicy GetRetryPolicy() { return(Policy .Handle <Exception>() .RetryAsync(3, (exception, retryCount) => { _logger.Warn($"Error connecting to Provider Idams Api: ({exception.Message}). Retrying...attempt {retryCount})"); } )); }
private void ValidateRequest(GetApprenticeshipsByUlnRequest request) { var validationMsg = $"Invalid Uln {request.Uln}"; if (String.IsNullOrWhiteSpace(request.Uln)) { throw new ValidationException(validationMsg); } var validationResult = _ulnValidator.Validate(request.Uln); if (validationResult != UlnValidationResult.Success) { _logger.Warn(validationMsg); throw new ValidationException(validationMsg); } }
private bool ValidateStartedApprenticeship(Apprenticeship apprenticeship, ApprenticeshipUpdate apprenticeshipUpdate) { var started = apprenticeship.StartDate.HasValue && apprenticeship.StartDate.Value <= new DateTime(_currentDateTime.Now.Year, _currentDateTime.Now.Month, 1); if (!started) { return(true); } if (apprenticeship.HasHadDataLockSuccess && (apprenticeshipUpdate.Cost != null || apprenticeshipUpdate.TrainingCode != null) ) { _logger.Warn($"Trying to update a started apprenticeship with a successful DataLock with values; Cost {apprenticeshipUpdate.Cost}, TrainingCode: {apprenticeshipUpdate.TrainingCode}"); return(false); } return(true); }