public async Task <string> Submit(IDynamicsClient dynamicsClient, ILogger logger, User user, ScreeningType screeningType, string programAreaId) { var candidate = await ObtainCandidate(dynamicsClient, logger); var submitter = await ObtainSubmitter(dynamicsClient, logger, user, programAreaId); var contact = await ObtainContact(dynamicsClient, logger); try { var screeningRequest = await DynamicsUtility.CreateScreeningRequestAsync( dynamicsClient, this, candidate.Contactid, submitter.SpiceMinistryemployeeid, contact.SpiceMinistryemployeeid, screeningType.ApplicantType, screeningType.CannabisApplicantType ); logger.LogInformation("Successfully created screening request {ScreeningId} from view model {@ScreeningRequest}", screeningRequest.Incidentid, this); return(screeningRequest.Incidentid); } catch (OdataerrorException ex) { logger.LogError(ex, string.Join(Environment.NewLine, "Failed to create screening request incident", "{@ErrorBody}"), ex.Body); throw; } }
public async Task <bool> Validate(IDynamicsClient dynamicsClient, Ministry dynamicsMinistry, ProgramArea dynamicsProgramArea, ScreeningType dynamicsScreeningType) { // validate nested data exists if (Candidate == null || Contact == null) { return(false); } // validate required properties var requiredProperties = new string[] { ClientMinistry, ProgramArea, ScreeningType, Reason, Candidate.FirstName, Candidate.LastName, Candidate.Email, Candidate.Position, Contact.FirstName, Contact.LastName, Contact.Email, }; if (requiredProperties.Any(string.IsNullOrWhiteSpace)) { return(false); } // validate range for candidate date of birth if (Candidate.DateOfBirth < DateTime.Today.AddYears(-100) || Candidate.DateOfBirth > DateTime.Today.AddYears(-10)) { return(false); } // validate submitted screening type matches an existing screening type in Dynamics which is valid for the user's org code if (dynamicsMinistry == null || dynamicsProgramArea == null || dynamicsScreeningType == null) { return(false); } // validate submitted ministry and program area match the associated entities in Dynamics for the submitted screening type if (ClientMinistry != dynamicsMinistry.Value || ProgramArea != dynamicsProgramArea.Value) { return(false); } // validate screening reason matches one of the possible screening reasons var screeningReason = await DynamicsUtility.GetScreeningReasonAsync(dynamicsClient, Reason); if (screeningReason == null) { return(false); } return(true); }