private CertificateData CombineCertificateData(CertificateData certData, CertificateData requestData, StandardOptions options) { var epaDetails = certData.EpaDetails ?? new EpaDetails(); if (epaDetails.Epas is null) { epaDetails.Epas = new List <EpaRecord>(); } var epaOutcome = certData.OverallGrade == CertificateGrade.Fail ? EpaOutcome.Fail : EpaOutcome.Pass; if (requestData.AchievementDate != null && !epaDetails.Epas.Any(rec => rec.EpaDate == requestData.AchievementDate.Value && rec.EpaOutcome == epaOutcome)) { var record = new EpaRecord { EpaDate = requestData.AchievementDate.Value, EpaOutcome = epaOutcome }; epaDetails.Epas.Add(record); // sort pass outcomes before fail outcomes as pass is the final state even if earlier than the fail var latestRecord = epaDetails.Epas .OrderByDescending(epa => epa.EpaOutcome != EpaOutcome.Fail ? 1 : 0) .ThenByDescending(epa => epa.EpaDate) .First(); epaDetails.LatestEpaDate = latestRecord.EpaDate; epaDetails.LatestEpaOutcome = latestRecord.EpaOutcome; } return(new CertificateData() { LearnerGivenNames = certData.LearnerGivenNames, LearnerFamilyName = certData.LearnerFamilyName, LearningStartDate = certData.LearningStartDate, StandardReference = certData.StandardReference, StandardName = certData.StandardName, StandardLevel = certData.StandardLevel, StandardPublicationDate = certData.StandardPublicationDate, FullName = certData.FullName, ProviderName = certData.ProviderName, ContactName = requestData.ContactName, ContactOrganisation = requestData.ContactOrganisation, Department = requestData.Department, ContactAddLine1 = requestData.ContactAddLine1, ContactAddLine2 = requestData.ContactAddLine2, ContactAddLine3 = requestData.ContactAddLine3, ContactAddLine4 = requestData.ContactAddLine4, ContactPostCode = requestData.ContactPostCode, Registration = requestData.Registration, AchievementDate = requestData.AchievementDate, CourseOption = CertificateHelpers.NormalizeCourseOption(options, requestData.CourseOption), Version = requestData.Version, OverallGrade = CertificateHelpers.NormalizeOverallGrade(requestData.OverallGrade), EpaDetails = epaDetails }); }
private CertificateData CombineCertificateData(CertificateData data, Ilr ilr, StandardCollation standard, Provider provider) { var epaDetails = data.EpaDetails ?? new EpaDetails(); if (epaDetails.Epas is null) { epaDetails.Epas = new List <EpaRecord>(); } var epaOutcome = data.OverallGrade == CertificateGrade.Fail ? EpaOutcome.Fail : EpaOutcome.Pass; if (data.AchievementDate != null && !epaDetails.Epas.Any(rec => rec.EpaDate == data.AchievementDate.Value && rec.EpaOutcome == epaOutcome)) { var record = new EpaRecord { EpaDate = data.AchievementDate.Value, EpaOutcome = epaOutcome }; epaDetails.Epas.Add(record); var latestRecord = epaDetails.Epas.OrderByDescending(epa => epa.EpaDate).First(); epaDetails.LatestEpaDate = latestRecord.EpaDate; epaDetails.LatestEpaOutcome = latestRecord.EpaOutcome; } return(new CertificateData() { LearnerGivenNames = ilr.GivenNames, LearnerFamilyName = ilr.FamilyName, LearningStartDate = ilr.LearnStartDate, StandardReference = standard.ReferenceNumber, StandardName = standard.Title, StandardLevel = standard.StandardData.Level.GetValueOrDefault(), StandardPublicationDate = standard.StandardData.EffectiveFrom, FullName = $"{ilr.GivenNames} {ilr.FamilyName}", ProviderName = provider.ProviderName, ContactName = data.ContactName, ContactOrganisation = data.ContactOrganisation, Department = data.Department, ContactAddLine1 = data.ContactAddLine1, ContactAddLine2 = data.ContactAddLine2, ContactAddLine3 = data.ContactAddLine3, ContactAddLine4 = data.ContactAddLine4, ContactPostCode = data.ContactPostCode, Registration = data.Registration, AchievementDate = data.AchievementDate, CourseOption = CertificateHelpers.NormalizeCourseOption(standard, data.CourseOption), OverallGrade = CertificateHelpers.NormalizeOverallGrade(data.OverallGrade), EpaDetails = epaDetails }); }
private CertificateData CombineCertificateData(CertificateData data, Domain.Entities.Learner learner, Standard standard, Provider provider, StandardOptions options, Certificate certificate) { var epaDetails = new EpaDetails(); if (certificate != null) { var certData = JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData); if (certData.EpaDetails != null) { epaDetails = certData.EpaDetails; } } if (epaDetails.Epas is null) { epaDetails.Epas = new List <EpaRecord>(); } var epaOutcome = data.OverallGrade == CertificateGrade.Fail ? EpaOutcome.Fail : EpaOutcome.Pass; if (data.AchievementDate != null && !epaDetails.Epas.Any(rec => rec.EpaDate == data.AchievementDate.Value && rec.EpaOutcome == epaOutcome)) { var record = new EpaRecord { EpaDate = data.AchievementDate.Value, EpaOutcome = epaOutcome }; epaDetails.Epas.Add(record); var latestRecord = epaDetails.Epas.OrderByDescending(epa => epa.EpaDate).First(); epaDetails.LatestEpaDate = latestRecord.EpaDate; epaDetails.LatestEpaOutcome = latestRecord.EpaOutcome; } return(new CertificateData() { LearnerGivenNames = learner.GivenNames, LearnerFamilyName = learner.FamilyName, LearningStartDate = learner.LearnStartDate, StandardReference = standard.IfateReferenceNumber, StandardName = standard.Title, StandardLevel = standard.Level, StandardPublicationDate = standard.EffectiveFrom, FullName = $"{learner.GivenNames} {learner.FamilyName}", ProviderName = provider.Name, ContactName = data.ContactName, ContactOrganisation = data.ContactOrganisation, Department = data.Department, ContactAddLine1 = data.ContactAddLine1, ContactAddLine2 = data.ContactAddLine2, ContactAddLine3 = data.ContactAddLine3, ContactAddLine4 = data.ContactAddLine4, ContactPostCode = data.ContactPostCode, Registration = data.Registration, AchievementDate = data.AchievementDate, CourseOption = CertificateHelpers.NormalizeCourseOption(options, data.CourseOption), OverallGrade = CertificateHelpers.NormalizeOverallGrade(data.OverallGrade), Version = data.Version, EpaDetails = epaDetails }); }