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"
            };
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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
            });
        }
Ejemplo n.º 4
0
 private bool IsValidAddEnglishAndMathsRequest(TqRegistrationPathway registrationPathway, AddLearnerRecordRequest request)
 {
     return(!request.HasLrsEnglishAndMaths && request.EnglishAndMathsStatus != null &&
            registrationPathway.TqRegistrationProfile.IsEnglishAndMathsAchieved == null &&
            registrationPathway.TqRegistrationProfile.IsRcFeed == null);
 }
Ejemplo n.º 5
0
 private bool IsValidEnglishAndMathsLrsEmailRequest(AddLearnerRecordRequest request)
 {
     return(request != null && request.HasLrsEnglishAndMaths && request.EnglishAndMathsLrsStatus != null && request.EnglishAndMathsStatus == null);
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 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));
 }