예제 #1
0
        public async Task <bool> Validate(IDynamicsClient dynamicsClient, Ministry siteMinderMinistry, ProgramArea siteMinderProgramArea)
        {
            // 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 ministry and program area match the values from siteminder
            if (ClientMinistry != siteMinderMinistry.Value || ProgramArea != siteMinderProgramArea.Value)
            {
                return(false);
            }

            // validate screening type matches one of the screening types for the program area
            if (!siteMinderProgramArea.ScreeningTypes.Any(t => t.Value == ScreeningType))
            {
                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);
        }
예제 #2
0
        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);
        }