public void RelatedOffenseVehiclesTest() { var result = ValidationField.RelatedOffenseVehicles(); result.FieldPath.Should().Be("relatedOffense"); result.SectionName.Should().Be("Vehicles"); result.ControlType.Should().Be(ControlType.RelatedOffense); }
private void SetCustoms() { #region Must Enter Stolen Property Record when UCR Code is 6d, Attempted/Completed is '02' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Property Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenPropertyExistsForOffense6d") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter Stolen Vehicle Record when UCR Code is 07a,07b,07c) and Attempted/Completed is 'C' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Vehicle Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenVehicleExistsForOffense7a7b7c") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter Stolen Property or Vehicle Record when UCR code is 03a,b,c,d and Attempted/Completed is 'C' ('Completed') ValidationMessage = new ValidationMessage { Message = string.Format("Must Enter Stolen Property or Vehicle Record"), TargetPath = "attemptedCompleted" }; TargetField = new ValidationField { FieldPath = "attemptedCompleted", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; AssociatedField2 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("stolenPropertyOrVehicleExistsForOffense3a3b3c3d") .ThatSelfEvaluates() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); //broadcast rules UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField2).ThatBroadcasts().ImplementStateValidationRule()); #endregion #region Must Enter a Weapon if UCR Class is 01, 02, 03, 04, 15, or 17 and Domestic Violence is checked TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.INCIDENT_EVENT, "domesticViolence"); ucrClassList = new List <string>() { "01", "02", "03", "04", "15", "17" }; ValidationMessage = new ValidationMessage( string.Format("{0} Must Be Entered for {1} incidents", TargetFieldLabel, AssociatedField1Label), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; AssociatedField1 = new ValidationField { FieldPath = "domesticViolence", FieldType = FieldType.Extended, SectionName = GenericSectionName.INCIDENT_EVENT, ControlType = ControlType.Checkbox, }; ValidationRule = new Validation(ValidationMessage, TargetField) .CustomValidation("mustEnterWeaponForDomesticViolenceEvents") .ThatSelfEvaluates() .AlwaysShowMessage() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeOffenses()).ThatBroadcasts().ImplementStateValidationRule()); UcrValidationRules.Add(new Validation(ValidationMessage, AssociatedField1).ThatBroadcasts().ImplementStateValidationRule()); #endregion }
private void SetRequired() { #region TimeOfDay is required when ViolationCode has a UCR Class of 05 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "timeOfDay"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ValidationMessage = new ValidationMessage( string.Format("'You Must Enter In {0} If The Offense Is A Burglary", TargetFieldLabel), "timeOfDay"); TargetField = new ValidationField { FieldPath = "timeOfDay", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), new List <string> { "05" }) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Structure should be left blank when UCR Class is 08 (Arson) and Sub Class is j,h, or i TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "structure"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); ucrClassList = new List <string> { "08" }; ucrSubclassList = new List <string> { "j.", "h.", "i." }; ValidationMessage = new ValidationMessage { Message = string.Format("{0} should be left blank for Arson offenses not involving structures", TargetFieldLabel), TargetPath = "structure" }; TargetField = new ValidationField { FieldPath = "structure", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Code }; ValidationRule = new Validation( ValidationMessage, TargetField) .NotRequired() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Value is required when Status is S (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "value"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("If {0} is stolen, {1} is required", AssociatedField1Label, TargetFieldLabel), "value"); TargetField = new ValidationField { FieldPath = "value", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} is required when {1} is 'S'", TargetFieldLabel, AssociatedField1Label), "value"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region RecoveredValue can only be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveredValue"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); TargetField = new ValidationField { FieldPath = "recoveredValue", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveredValue"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region RecoveryDateTime can only be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveryDateTime"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); TargetField = new ValidationField { FieldPath = "recoveryDateTime", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Date, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} can only be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .DoesNotContain(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region RecoveredDate must be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "recoveryDateTime"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); TargetField = new ValidationField { FieldPath = "recoveryDateTime", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Date, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; AssociatedField1.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); // Vehicles TargetField.SectionName = GenericSectionName.VEHICLES; AssociatedField1.SectionName = GenericSectionName.VEHICLES; ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "recoveryDateTime"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseVehicles()).ThatBroadcasts() .ImplementStateValidationRule()); UcrValidationRules.Add(ValidationRule); #endregion #region EstimatedValue must be entered when Status is S or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "estimatedValue"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Stolen' or 'Stolen/Recovered", TargetFieldLabel, AssociatedField1Label), "estimatedValue"); TargetField = new ValidationField { FieldPath = "estimatedValue", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Text, }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "S", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region VehicleRecovery must be entered when Status is R or SR TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "vehicleRecovery"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.VEHICLES, "status"); ValidationMessage = new ValidationMessage( string.Format("{0} must be entered when {1} is 'Recovered' or 'Stolen/Recovered'", TargetFieldLabel, AssociatedField1Label), "vehicleRecovery"); TargetField = new ValidationField { FieldPath = "vehicleRecovery", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code }; AssociatedField1 = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.VEHICLES, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(AssociatedField1, new List <string> { "R", "SR" }) .RelatedOffenseRequired() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AssociatedField1, ValidationRule)); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Person Number cannot be blank (Suspect) UcrValidationRules.Add( new Validation( new ValidationMessage { Message = string.Format("{0} is required", ResolveFieldLabel(TemplateReference, GenericSectionName.SUSPECTS, "personNumber")), TargetPath = "personNumber" }, new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.SUSPECTS, ControlType = ControlType.Text }) .Required().ImplementStateValidationRule()); #endregion #region Person Number cannot be 0 (Victim) // this rule was broken in 2 rules to handle more than one operation TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "personNumber"); ValidationMessage = new ValidationMessage(string.Format("{0} cannot be '0'", TargetFieldLabel), "personNumber"); TargetField = new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Text }; ValidationRule = new Validation(ValidationMessage, TargetField) .Comparison(ValidationOperand.NotEqual, "0") .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); #endregion #region 'If Person Number is Not 0, Age or Sex or Race Must be Known TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "personNumber"); var ageLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "age"); var raceLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "race"); var sexLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.VICTIMS, "sex"); ValidationMessage = new ValidationMessage(string.Format("If {0} is Not 0, {1} or {2} or {3} Must be Known", TargetFieldLabel, ageLabel, raceLabel, sexLabel), "personNumber"); TargetField = new ValidationField { FieldPath = "personNumber", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Text }; var AgeField = new ValidationField { FieldPath = "age", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; var RaceField = new ValidationField { FieldPath = "race", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; var SexField = new ValidationField { FieldPath = "sex", SectionName = GenericSectionName.VICTIMS, ControlType = ControlType.Code }; ValidationRule = new Validation(ValidationMessage, TargetField) .Comparison(ValidationOperand.Equal, "0") .WithConditions() .NotRequired(AgeField) .NotRequired(SexField) .NotRequired(RaceField) .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(AgeField, ValidationRule)); UcrValidationRules.Add(Validation.CreateAssociatedRule(RaceField, ValidationRule)); UcrValidationRules.Add(Validation.CreateAssociatedRule(SexField, ValidationRule)); #endregion #region Status must be entered (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "status"); ValidationMessage = new ValidationMessage(string.Format("Must Enter {0}", TargetFieldLabel), "status"); TargetField = new ValidationField { FieldPath = "status", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .ThatBroadcasts() .RelatedOffenseRequired() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage(string.Format("Must Enter {0}", TargetFieldLabel), "status"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Type must be entered (Property, Guns) TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.PROPERTY, "type"); ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "type"); TargetField = new ValidationField { FieldPath = "type", SectionName = GenericSectionName.PROPERTY, ControlType = ControlType.Code, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); // Property UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseProperty()).ThatBroadcasts() .ImplementStateValidationRule()); // Guns TargetField.SectionName = GenericSectionName.GUNS; ValidationMessage = new ValidationMessage(string.Format("{0} is required", TargetFieldLabel), "type"); ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .RelatedOffenseRequired() .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add( new Validation(ValidationMessage, ValidationField.RelatedOffenseGuns()).ThatBroadcasts() .ImplementStateValidationRule()); #endregion #region Must Enter a Weapon if UCR Class is 01a TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); ucrClassList = new List <string>() { "01" }; ucrSubclassList = new List <string>() { "a." }; ValidationMessage = new ValidationMessage( string.Format("If UCR code is 01a, Weapon Must Be Entered", TargetFieldLabel), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region Cannot enter a Weapon if UCR Class is 24 TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); ucrClassList = new List <string>() { "24" }; ValidationMessage = new ValidationMessage(string.Format("Cannot enter a {0} if UCR Class is '24'", TargetFieldLabel), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .NotRequired() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(Validation.CreateAssociatedRule(ValidationField.ViolationCodeOffenses(), ValidationRule)); #endregion #region WeaponTypes must be 06 when ViolationCode has a UCR Class of 04 and Subclass of b -- per PM, needs to fire when no weapon is entered as well TargetFieldLabel = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "weaponTypes"); AssociatedField1Label = ResolveFieldLabel(TemplateReference, GenericSectionName.OFFENSES, "violationCodeReference"); classList = new List <string> { "06" }; ucrClassList = new List <string> { "04" }; ucrSubclassList = new List <string> { "b." }; ValidationMessage = new ValidationMessage(string.Format("If UCR code is 04b, the weapon must be 'Knife or other cutting or stabbing instrument'"), "weaponTypes"); TargetField = new ValidationField { FieldPath = "weaponTypes", SectionName = GenericSectionName.OFFENSES, ControlType = ControlType.Multiselect, }; ValidationRule = new Validation(ValidationMessage, TargetField) .Required() .WithConditions() .Contains(ValidationField.ViolationCodeOffenses(ucrClassProperty), ucrClassList) .Contains(ValidationField.ViolationCodeOffenses(ucrSubclassProperty), ucrSubclassList) .ThatBroadcasts() .ImplementStateValidationRule(); UcrValidationRules.Add(ValidationRule); UcrValidationRules.Add(new Validation(ValidationMessage, ValidationField.ViolationCodeOffenses()).ThatBroadcasts().ImplementStateValidationRule()); #endregion }