private async Task <Certificate> UpdateCertificate(UpdateBatchCertificateRequest request)
        {
            _logger.LogInformation("UpdateCertificate Before Get Standard from API");
            var standard = await _standardService.GetStandard(request.StandardCode);

            _logger.LogInformation("UpdateCertificate Before Get Certificate from db");
            var certificate = await _certificateRepository.GetCertificate(request.Uln, request.StandardCode);

            if (standard != null && certificate != null)
            {
                var certData = CombineCertificateData(JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData), request.CertificateData, standard);

                _logger.LogInformation("UpdateCertificate Before Update CertificateData");

                // need to update EPA Reference too
                certData.EpaDetails.EpaReference = certificate.CertificateReference;
                certificate.CertificateData      = JsonConvert.SerializeObject(certData);

                // adjust Status appropriately
                if (certificate.Status == CertificateStatus.Deleted)
                {
                    certificate.Status = CertificateStatus.Draft;
                }

                _logger.LogInformation("UpdateCertificate Before Update Cert in db");
                await _certificateRepository.Update(certificate, ExternalApiConstants.ApiUserName, CertificateActions.Amend);

                return(await CertificateHelpers.ApplyStatusInformation(_certificateRepository, _contactQueryRepository, certificate));
            }
            else
            {
                _logger.LogWarning($"UpdateCertificate Did not find Certificate for Uln {request.Uln} and StandardCode {request.StandardCode}");
                throw new NotFound();
            }
        }
Beispiel #2
0
        private async Task <Certificate> CreateNewCertificate(CreateBatchCertificateRequest request)
        {
            _logger.LogInformation("CreateNewCertificate Before Get Ilr from db");
            var ilr = await _ilrRepository.Get(request.Uln, request.StandardCode);

            if (ilr is null)
            {
                _logger.LogWarning($"CreateNewCertificate Did not find ILR for Uln {request.Uln} and StandardCode {request.StandardCode}");
                return(null);
            }

            _logger.LogInformation("CreateNewCertificate Before Get Organisation from db");
            var organisation = await _organisationQueryRepository.GetByUkPrn(request.UkPrn);

            _logger.LogInformation("CreateNewCertificate Before Get Standard from API");
            var standard = await _standardService.GetStandard(ilr.StdCode);

            _logger.LogInformation("CreateNewCertificate Before Get Provider from API");
            var provider = await GetProviderFromUkprn(ilr.UkPrn);

            var certData = CombineCertificateData(request.CertificateData, ilr, standard, provider);

            var certificate = await _certificateRepository.GetCertificate(request.Uln, request.StandardCode);

            if (certificate == null)
            {
                _logger.LogInformation("CreateNewCertificate Before create new Certificate");
                certificate = await _certificateRepository.New(
                    new Certificate()
                {
                    Uln                  = request.Uln,
                    StandardCode         = request.StandardCode,
                    ProviderUkPrn        = ilr.UkPrn,
                    OrganisationId       = organisation.Id,
                    CreatedBy            = ExternalApiConstants.ApiUserName,
                    CertificateData      = JsonConvert.SerializeObject(certData),
                    Status               = CertificateStatus.Draft, // NOTE: Web & Staff always creates Draft first
                    CertificateReference = string.Empty,
                    LearnRefNumber       = ilr.LearnRefNumber,
                    CreateDay            = DateTime.UtcNow.Date
                });
            }
            else
            {
                _logger.LogInformation("CreateNewCertificate Before resurrecting deleted Certificate");
                certData.EpaDetails.EpaReference = certificate.CertificateReference;
                certificate.CertificateData      = JsonConvert.SerializeObject(certData);
                certificate.Status = CertificateStatus.Draft;
                await _certificateRepository.Update(certificate, ExternalApiConstants.ApiUserName, CertificateActions.Start);
            }

            _logger.LogInformation(LoggingConstants.CertificateStarted);
            _logger.LogInformation($"Certificate with ID: {certificate.Id} Started with reference of {certificate.CertificateReference}");

            return(await CertificateHelpers.ApplyStatusInformation(_certificateRepository, _contactQueryRepository, certificate));
        }
        private async Task <Certificate> GetCertificate(GetBatchCertificateRequest request)
        {
            _logger.LogInformation("GetCertificate Before Get Certificate from db");
            var certificate = await _certificateRepository.GetCertificate(request.Uln, request.StandardCode);

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

            var allowedCertificateStatus = new string[] { CertificateStatus.Draft, CertificateStatus.Submitted, CertificateStatus.Printed, CertificateStatus.Reprint };

            if (certificate != null && searchingOrganisation != null && allowedCertificateStatus.Contains(certificate.Status))
            {
                var certData = JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData);

                if (string.Equals(certData.LearnerFamilyName, request.FamilyName, StringComparison.InvariantCultureIgnoreCase))
                {
                    certificate = await CertificateHelpers.ApplyStatusInformation(_certificateRepository, _contactQueryRepository, certificate);

                    if (!EpaOutcome.Pass.Equals(certData.EpaDetails?.LatestEpaOutcome, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // As EPA has not passed, only give access to basic information & EPA Details
                        certificate = RedactCertificateInformation(certificate, true);
                    }

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

                        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;
                        }
                    }
                }
                else
                {
                    certificate = null;
                }
            }
            else
            {
                certificate = null;
            }

            return(certificate);
        }
Beispiel #4
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);
        }
        private async Task <Certificate> SubmitCertificate(SubmitBatchCertificateRequest request)
        {
            _logger.LogInformation("SubmitCertificate Before Get Certificate from db");
            var certificate = await _certificateRepository.GetCertificate(request.Uln, request.StandardCode);

            if (certificate != null)
            {
                _logger.LogInformation("SubmitCertificate Before Update Certificate Status");
                certificate.Status = CertificateStatus.Submitted;

                _logger.LogInformation("SubmitCertificate Before Update Cert in db");
                var submittedCertificate = await _certificateRepository.Update(certificate, ExternalApiConstants.ApiUserName, CertificateActions.Submit);

                return(await CertificateHelpers.ApplyStatusInformation(_certificateRepository, _contactQueryRepository, submittedCertificate));
            }
            else
            {
                _logger.LogWarning($"SubmitCertificate Did not find Certificate for Uln {request.Uln} and StandardCode {request.StandardCode}");
                return(null);
            }
        }