public override void Setup() { _tokenServiceClient = Substitute.For <ITokenServiceClient>(); _configuration = new ResultsAndCertificationConfiguration { ResultsAndCertificationInternalApiSettings = new ResultsAndCertificationInternalApiSettings { Uri = "http://tlevel.api.com" } }; _mockHttpResult = new AddLearnerRecordResponse { Uln = 1234567891, Name = "Test User", IsSuccess = true }; _model = new AddLearnerRecordRequest { Ukprn = 58974561, Uln = 1234567891, HasLrsEnglishAndMaths = false, EnglishAndMathsStatus = EnglishAndMathsStatus.AchievedWithSend, IndustryPlacementStatus = IndustryPlacementStatus.Completed, PerformedBy = "Test User" }; }
private async Task <bool> SendEmailAsync(int profileId, AddLearnerRecordRequest request) { var tokens = new Dictionary <string, dynamic> { { "profile_id", profileId }, { "english_and_maths_lrs_status", request.EnglishAndMathsLrsStatus.ToString() }, { "sender_name", request.PerformedBy }, { "sender_email_address", request.PerformedUserEmail } }; return(await _notificationService.SendEmailNotificationAsync(NotificationTemplateName.EnglishAndMathsLrsDataQueried.ToString(), _resultsAndCertificationConfiguration.TlevelQueriedSupportEmailAddress, tokens)); }
public async Task <AddLearnerRecordResponse> AddLearnerRecordAsync(AddLearnerRecordRequest request) { var pathway = await _tqRegistrationPathwayRepository .GetManyAsync(x => x.TqRegistrationProfile.UniqueLearnerNumber == request.Uln && x.TqProvider.TlProvider.UkPrn == request.Ukprn, navigationPropertyPath : new Expression <Func <TqRegistrationPathway, object> >[] { n => n.TqRegistrationProfile, n => n.IndustryPlacements }) .OrderByDescending(o => o.CreatedOn) .FirstOrDefaultAsync(); var isSuccess = false; if (!IsValidAddLearnerRecordRequest(pathway, request)) { return new AddLearnerRecordResponse { IsSuccess = isSuccess } } ; if (IsValidEnglishAndMathsLrsEmailRequest(request)) { isSuccess = await SendEmailAsync(pathway.TqRegistrationProfileId, request); } else { if (IsValidAddEnglishAndMathsRequest(pathway, request)) { pathway.TqRegistrationProfile.IsEnglishAndMathsAchieved = request.EnglishAndMathsStatus.Value == EnglishAndMathsStatus.Achieved || request.EnglishAndMathsStatus.Value == EnglishAndMathsStatus.AchievedWithSend; pathway.TqRegistrationProfile.IsSendLearner = request.EnglishAndMathsStatus.Value == EnglishAndMathsStatus.AchievedWithSend ? true : (bool?)null; pathway.TqRegistrationProfile.IsRcFeed = true; pathway.TqRegistrationProfile.ModifiedBy = request.PerformedBy; pathway.TqRegistrationProfile.ModifiedOn = DateTime.UtcNow; } pathway.IndustryPlacements.Add(new IndustryPlacement { TqRegistrationPathwayId = pathway.Id, Status = request.IndustryPlacementStatus, CreatedBy = request.PerformedBy }); isSuccess = await _tqRegistrationPathwayRepository.UpdateWithSpecifedCollectionsOnlyAsync(pathway, false, p => p.TqRegistrationProfile, p => p.IndustryPlacements) > 0; } return(new AddLearnerRecordResponse { Uln = request.Uln, Name = $"{pathway.TqRegistrationProfile.Firstname} {pathway.TqRegistrationProfile.Lastname}", IsSuccess = isSuccess }); }
private bool IsValidAddEnglishAndMathsRequest(TqRegistrationPathway registrationPathway, AddLearnerRecordRequest request) { return(!request.HasLrsEnglishAndMaths && request.EnglishAndMathsStatus != null && registrationPathway.TqRegistrationProfile.IsEnglishAndMathsAchieved == null && registrationPathway.TqRegistrationProfile.IsRcFeed == null); }
private bool IsValidEnglishAndMathsLrsEmailRequest(AddLearnerRecordRequest request) { return(request != null && request.HasLrsEnglishAndMaths && request.EnglishAndMathsLrsStatus != null && request.EnglishAndMathsStatus == null); }
private bool IsValidAddLearnerRecordRequest(TqRegistrationPathway registrationPathway, AddLearnerRecordRequest request) { if (!IsValidPathwayStatus(registrationPathway)) { return(false); } var isValidEnglishAndMathsLrsEmailRequest = IsValidEnglishAndMathsLrsEmailRequest(request); var isValidEnglishAndMaths = isValidEnglishAndMathsLrsEmailRequest || (request.HasLrsEnglishAndMaths && request.EnglishAndMathsStatus == null) || (!request.HasLrsEnglishAndMaths && request.EnglishAndMathsStatus != null && request.EnglishAndMathsLrsStatus == null); var isValidIndustryPlacement = request.IndustryPlacementStatus != IndustryPlacementStatus.NotSpecified && !registrationPathway.IndustryPlacements.Any(); return(isValidEnglishAndMathsLrsEmailRequest ? isValidEnglishAndMaths : isValidEnglishAndMaths && isValidIndustryPlacement); }
public async Task <AddLearnerRecordResponse> AddLearnerRecordAsync(AddLearnerRecordRequest request) { return(await _trainingProviderService.AddLearnerRecordAsync(request)); }
public async Task <AddLearnerRecordResponse> AddLearnerRecordAsync(AddLearnerRecordRequest request) { return(await PostAsync <AddLearnerRecordRequest, AddLearnerRecordResponse>(ApiConstants.AddLearnerRecordUri, request)); }