public bool Validate(MessageLearner ObjectToValidate)
        {
            //check DoB rule, proceed only if the Dob is not null
            if (_learnerDoBNotNullRule.Evaluate(ObjectToValidate))
            {
                return(true);
            }

            //check agerule, if learner is above 16 then skip this rule
            if (_IsLearnerBelowSchoolAge.Evaluate(ObjectToValidate))
            {
                return(true);
            }

            //check the DD07 rule and get the valid prog type LDs
            ObjectToValidate.LearningDelivery = ObjectToValidate.LearningDelivery.Where(ld => !_dd07IsYRule.Evaluate(ld)).ToArray();

            //execute DD04 and fetch programme start date.
            if (_dd04IsInRangeRule.Evaluate(ObjectToValidate))
            {
                _validationErrorHandler.Handle(ObjectToValidate, RuleNameConstants.DateOfBirth_48);
                return(false);
            }

            return(true);
        }
        public string Evaluate(Learner learner)
        {
            var result = "N";

            //get the emprecords with allowed empstat and emptype code
            var empRecordsWithAllowedEmpStatAndEsmType =
                _dd21GetLearningDeliveriesWithSpecificEmp.Evaluate(learner.LearnerEmploymentStatuses);

            if (empRecordsWithAllowedEmpStatAndEsmType?.Count == 0)
            {
                return(result);
            }

            foreach (var learningDelivery in learner.LearningDeliveries)
            {
                //check if the LDFam type and code are allowed for this LD.
                var isValidFamCodeAndType = learningDelivery.LearningDeliveryFAMs.Any(ldFam =>
                                                                                      ldFam.LearnDelFAMCode != _FamCodeShouldNotBe && ldFam.LearnDelFAMType == _allowedFamType);

                if (!isValidFamCodeAndType)
                {
                    continue;
                }

                //find matching employment record for the learningdelivery
                var matchedEmployementRecord =
                    _dd28PickMatchingEmpRecord.Evaluate(new DD28SubModel()
                {
                    LearnerEmploymentStatusObj = empRecordsWithAllowedEmpStatAndEsmType,
                    LearningDeliveryObject     = learningDelivery
                });

                if (matchedEmployementRecord == null)
                {
                    continue;
                }

                //if any matched emploment record is found then return
                result = "Y";
                return(result);
            }
            //if it reaches here then result is N
            return(result);
        }
        public string Evaluate(Learner objectToValidate)
        {
            var result = "N";

            foreach (var learningDelivery in objectToValidate.LearningDeliveries)
            {
                //find matching employment record for the learningdelivery
                var matchedEmployementRecord =
                    _dd28PickMatchingEmpRecord.Evaluate(new DD28SubModel()
                {
                    LearnerEmploymentStatusObj = objectToValidate.LearnerEmploymentStatuses,
                    LearningDeliveryObject     = learningDelivery
                });

                if (matchedEmployementRecord == null)
                {
                    return(result);
                }

                //pass the matched emp records and learning delivery to subrules
                var isAnyCreteriaValid = _dd28CriteriaRules.Any(criteria => criteria.Evaluate(new DD28SubModel()
                {
                    LearningDeliveryObject     = learningDelivery,
                    LearnerEmploymentStatusObj = new List <LearnerEmploymentStatus>()
                    {
                        matchedEmployementRecord
                    }
                }));

                if (!isAnyCreteriaValid)
                {
                    continue;
                }
                //if any rule returns true then return Y
                result = "Y";
                return(result);
            }
            //if it reaches here then result is N
            return(result);
        }
예제 #4
0
        public ValidationResult Validate(Learner ObjectToValidate)
        {
            var result = new ValidationResult()
            {
                IsValid  = true,
                RuleName = "DateOfBirth_48"
            };


            //check DoB rule, proceed only if the Dob is not null
            if (_learnerDoBNotNullRule.Evaluate(ObjectToValidate))
            {
                return(result);
            }

            //check agerule, if learner is above 16 then skip this rule
            if (_IsLearnerBelowSchoolAge.Evaluate(ObjectToValidate))
            {
                return(result);
            }

            //check the DD07 rule and get the valid prog type LDs
            var validProgTypeLDs = ObjectToValidate.LearningDeliveries.Where(ld => !_dd07IsYRule.Evaluate(ld)).ToList();


            //execute DD04 and fetch programme start date.
            if (_dd04IsInRangeRule.Evaluate(validProgTypeLDs))
            {
                result.IsValid       = false;
                result.ErrorMessages = new List <string>()
                {
                    _ErrorMessage
                };
                return(result);
            }

            return(result);
        }