public async Task <IActionResult> GetLearner(long uln, string familyName, [SwaggerParameter("Standard Code or Standard Reference Number")] string standard)
        {
            var getRequest = new GetBatchLearnerRequest {
                UkPrn = _headerInfo.Ukprn, Uln = uln, FamilyName = familyName, Standard = standard
            };
            var response = await _apiClient.GetLearner(getRequest);

            if (response.ValidationErrors.Any())
            {
                ApiResponse error = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", response.ValidationErrors));
                return(StatusCode(error.StatusCode, error));
            }
            else if (response.Learner is null)
            {
                return(NotFound());
            }
            else if (response.Learner.Certificate is null)
            {
                return(Ok(response.Learner));
            }
            else
            {
                if (CertificateHelpers.IsDraftCertificateDeemedAsReady(response.Learner.Certificate))
                {
                    response.Learner.Certificate.Status.CurrentStatus = CertificateStatus.Ready;
                }
                else if (CertificateStatus.HasPrintProcessStatus(response.Learner.Certificate.Status.CurrentStatus))
                {
                    response.Learner.Certificate.Status.CurrentStatus = CertificateStatus.Submitted;
                }

                return(Ok(response.Learner));
            }
        }
Example #2
0
        private async Task <Certificate> GetCertificate(GetBatchCertificateRequest request)
        {
            _logger.LogInformation("GetCertificate Before Get Certificate from db");
            var certificate = await _certificateRepository.GetCertificate(request.Uln, request.StandardCode, request.FamilyName, request.IncludeLogs);

            _logger.LogInformation("GetCertificate Before Get Searching Organisation from db");
            var searchingOrganisation = await _organisationQueryRepository.GetByUkPrn(request.UkPrn);

            var allowedCertificateStatus = new[] { CertificateStatus.Draft, CertificateStatus.Submitted }.Concat(CertificateStatus.PrintProcessStatus);

            if (certificate == null || searchingOrganisation == null || !allowedCertificateStatus.Contains(certificate.Status))
            {
                return(null);
            }

            var certData = JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData);

            certificate = await CertificateHelpers.ApplyStatusInformation(_certificateRepository, _contactQueryRepository, certificate);

            if ((certificate.Status == CertificateStatus.Submitted || CertificateStatus.HasPrintProcessStatus(certificate.Status)) && certData.OverallGrade == CertificateGrade.Fail)
            {
                return(null);
            }
            else if (certificate.Status == CertificateStatus.Draft &&
                     EpaOutcome.Pass.Equals(certData.EpaDetails?.LatestEpaOutcome, StringComparison.InvariantCultureIgnoreCase) &&
                     certData.OverallGrade == null)
            {
                return(null);
            }

            if (certificate.OrganisationId != searchingOrganisation.Id)
            {
                var providedStandards = await _standardRepository.GetEpaoRegisteredStandards(searchingOrganisation.EndPointAssessorOrganisationId, int.MaxValue, 1);

                if (providedStandards.PageOfResults.Any(s => s.StandardCode == certificate.StandardCode))
                {
                    // Shared standard but not the EPAO who created the certificate
                    certificate = RedactCertificateInformation(certificate, false);
                }
                else
                {
                    certificate = null;
                }
            }

            return(certificate);
        }
        public async Task <IActionResult> GetCertificate(long uln, string familyName, [SwaggerParameter("Standard Code or Standard Reference Number")] string standard)
        {
            var getRequest = new GetBatchCertificateRequest {
                UkPrn = _headerInfo.Ukprn, Uln = uln, FamilyName = familyName, Standard = standard
            };

            var response = await _apiClient.GetCertificate(getRequest);

            if (response.ValidationErrors.Any())
            {
                ApiResponse error = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", response.ValidationErrors));
                return(StatusCode(error.StatusCode, error));
            }
            else if (response.Certificate is null)
            {
                return(NoContent());
            }

            if (response.Certificate.Status.CurrentStatus == CertificateStatus.Printed)
            {
                response.Certificate.Delivered = new Delivered {
                    Status = "WaitingForDelivery"
                };
            }

            if (CertificateStatus.HasPrintProcessStatus(response.Certificate.Status.CurrentStatus) is false) // status could be Draft or Deleted (or Privately Funded statuses)
            {
                var certificateData = response.Certificate.CertificateData;

                if (!string.IsNullOrEmpty(certificateData.Standard?.StandardReference) && !string.IsNullOrEmpty(certificateData?.LearningDetails?.Version))
                {
                    var standardOptions = await _apiClient.GetStandardOptionsByStandardIdAndVersion(certificateData.Standard.StandardReference, certificateData.LearningDetails.Version);

                    var hasOptions = standardOptions != null && standardOptions.CourseOption?.Count() > 0;

                    if (CertificateHelpers.IsDraftCertificateDeemedAsReady(response.Certificate, hasOptions))
                    {
                        response.Certificate.Status.CurrentStatus = CertificateStatus.Ready;
                    }
                }
            }

            return(Ok(response.Certificate));
        }