public AmendmentOutcome ApplyRules(rscd_Amendment amendmentDto, Amendment amendment) { var ruleSet = _rules.FirstOrDefault(x => x.AmendmentType == amendment.AmendmentType && x.AmendmentReason == amendment.InclusionReasonId); if (ruleSet != null) { var outcome = ruleSet.Apply(amendment); if (outcome.OutcomeStatus != OutcomeStatus.AwaitingValidationPass) { if (outcome.OutcomeStatus == OutcomeStatus.AutoAccept) { amendmentDto.rscd_Outcome = rscd_Outcome.Autoapproved; } else if (outcome.OutcomeStatus == OutcomeStatus.AutoReject) { amendmentDto.rscd_Outcome = rscd_Outcome.Autorejected; } else { amendmentDto.rscd_Outcome = rscd_Outcome.AwaitingDfEreview; } } return(outcome); } return(new AmendmentOutcome(OutcomeStatus.AwatingDfeReview, $"No Accept or Reject rules found for this Reason {amendment.InclusionReasonId}")); }
private bool ValidAmendmentForCheckingWindow(CheckingWindow checkingWindow, rscd_Amendment amendment) { switch (checkingWindow) { case CheckingWindow.KS4June: return(amendment.rscd_Checkingwindow == rscd_Checkingwindow.KS4June); case CheckingWindow.KS4Late: return(amendment.rscd_Checkingwindow == rscd_Checkingwindow.KS4June && new[] { rscd_Outcome.Approvedandfinal, rscd_Outcome.Rejectedandfinal, rscd_Outcome.Autoapproved, rscd_Outcome.Autorejected }.Any(s => s == amendment.rscd_Outcome) || amendment.rscd_Checkingwindow == rscd_Checkingwindow.KS4Late); case CheckingWindow.KS5: return(amendment.rscd_Checkingwindow == rscd_Checkingwindow.KS5); } return(false); }
private AmendmentDetail GetAmendmentDetails(rscd_Amendment amendment) { using (var context = new CrmServiceContext(_organizationService)) { return(CurrentBuilder.CreateAmendmentDetails(context, amendment)); } }
private string GetStatus(CheckingWindow checkingWindow, rscd_Amendment amendment) { // TODO: Branching on checking window is ugly - we need to refactor this class if (checkingWindow == CheckingWindow.KS4Late && amendment.rscd_Checkingwindow == rscd_Checkingwindow.KS4June) { switch (amendment.rscd_Outcome) { case rscd_Outcome.AwaitingDfEreview: case rscd_Outcome.AwaitingReviewer2: case rscd_Outcome.AwaitingReviewer3: return("Requested"); default: return(amendment.rscd_Outcome.ToString()); } } switch (amendment.rscd_Outcome) { case rscd_Outcome.Awaitingevidence: case rscd_Outcome.Cancelled: return(amendment.rscd_Outcome.ToString()); default: return("Requested"); } }
private Amendment Convert(CheckingWindow checkingWindow, rscd_Amendment amendment) { CurrentBuilder = RetrieveBuilderForAmendment(amendment.rscd_Amendmenttype); var amendmentDomain = CurrentBuilder.CreateAmendment(); amendmentDomain.Id = amendment.Id.ToString(); amendmentDomain.CheckingWindow = amendment.rscd_Checkingwindow.Value.ToDomainCheckingWindow(); amendmentDomain.Reference = amendment.rscd_Referencenumber; amendmentDomain.URN = amendment.rscd_URN; amendmentDomain.Pupil = new Pupil { Forename = amendment.rscd_Firstname, Surname = amendment.rscd_Lastname, Gender = amendment.rscd_Gender.Value.ToDomainGenderType(), DOB = amendment.rscd_Dateofbirth.Value, Age = amendment.rscd_Age.HasValue ? amendment.rscd_Age.Value : 0, AdmissionDate = amendment.rscd_Dateofadmission.GetValueOrDefault(), YearGroup = amendment.rscd_Yeargroup, UPN = amendment.rscd_UPN, ULN = amendment.rscd_ULN }; amendmentDomain.EvidenceStatus = amendment.rscd_Evidencestatus.Value.ToDomainEvidenceStatus(); amendmentDomain.CreatedDate = amendment.CreatedOn.Value; amendmentDomain.Status = GetStatus(checkingWindow, amendment); amendmentDomain.AmendmentDetail = GetAmendmentDetails(amendment); return(amendmentDomain); }
public AmendmentOutcome BuildAmendments(Amendment amendment) { using (var context = new CrmServiceContext(_organizationService)) { AmendmentOutcome outcome; var amendmentDto = new rscd_Amendment { rscd_Checkingwindow = amendment.CheckingWindow.ToCRMCheckingWindow(), rscd_Amendmenttype = amendment.AmendmentType.ToCRMAmendmentType(), rscd_Academicyear = _allocationYear, rscd_URN = amendment.URN, OwnerId = _firstLineTeam }; outcome = _outcomeService.ApplyRules(amendmentDto, amendment); if (amendment.IsUserConfirmed && outcome.IsComplete && outcome.FurtherQuestions == null) { MapAmendmentToDto(amendment, amendmentDto); var amendmentTypeEntity = MapAmendmentTypeToDto(amendment); context.AddObject(amendmentTypeEntity); context.AddObject(amendmentDto); // Save var result = context.SaveChanges(); if (result.HasError) { throw result.FirstOrDefault(e => e.Error != null)?.Error ?? new ApplicationException(); } if (amendmentDto.rscd_Outcome == rscd_Outcome.Autoapproved || amendmentDto.rscd_Outcome == rscd_Outcome.Autorejected) { amendmentDto.StateCode = rscd_AmendmentState.Inactive; amendmentDto.rscd_recorded_by = _autoRecordedUser; _organizationService.Update(amendmentDto); } var relationship = new Relationship(RelationshipKey); _organizationService.Associate(amendmentTypeEntity.LogicalName, amendmentTypeEntity.Id, relationship, new EntityReferenceCollection { new EntityReference(amendmentDto.LogicalName, amendmentDto.Id) }); outcome.IsAmendmentCreated = true; outcome.NewAmendmentId = amendmentDto.Id; _logger.LogInformation("Amendment requested - ID: {amendmentId}", amendmentDto.Id); } return(outcome); } }
protected override void MapAmendmentToDto(Amendment amendment, rscd_Amendment amendmentDto) { amendmentDto.rscd_UPN = amendment.Pupil.UPN; amendmentDto.rscd_ULN = amendment.Pupil.ULN; amendmentDto.rscd_Name = amendment.Pupil.FullName; amendmentDto.rscd_Firstname = amendment.Pupil.Forename; amendmentDto.rscd_Lastname = amendment.Pupil.Surname; amendmentDto.rscd_Gender = amendment.Pupil.Gender.ToCRMGenderType(); amendmentDto.rscd_Dateofbirth = amendment.Pupil.DOB; amendmentDto.rscd_Age = amendment.Pupil.Age; if (Ks4Windows.Any(w => w == amendmentDto.rscd_Checkingwindow)) { amendmentDto.rscd_Dateofadmission = amendment.Pupil.AdmissionDate; amendmentDto.rscd_Yeargroup = amendment.Pupil.YearGroup; } amendmentDto.rscd_rm_scrutiny_reason_code = amendment.AmendmentDetail.GetField <int?>(RemovePupilAmendment.FIELD_ReasonCode); amendmentDto.rscd_OutcomeReason = amendment.AmendmentDetail.GetField <string>(RemovePupilAmendment.FIELD_OutcomeDescription); amendmentDto.rscd_Evidencestatus = amendment.EvidenceStatus.ToCRMEvidenceStatus(); }
public abstract AmendmentDetail CreateAmendmentDetails(CrmServiceContext context, rscd_Amendment amendment);
protected abstract void MapAmendmentToDto(Amendment amendment, rscd_Amendment amendmentDto);
public override AmendmentDetail CreateAmendmentDetails(CrmServiceContext context, rscd_Amendment amendment) { if (amendment.rscd_Amendmenttype == rscd_Amendmenttype.Removeapupil) { if (amendment.rscd_Removepupil != null) { var removePupil = context.rscd_RemovepupilSet.FirstOrDefault(x => x.Id == amendment.rscd_Removepupil.Id); return(removePupil.ToAmendmentDetail()); } } return(new AmendmentDetail()); }