Exemple #1
0
        public override bool Validate()
        {
            errors.Clear();

            //if (this.Person == null && this.PersonReference.EntityKey == null)
            //{
            //    errors.Add(new RuleViolation(this.Id, "Person", "", "Required"));
            //}

            if (string.IsNullOrEmpty(this.Type))
            {
                errors.Add(new RuleViolation(this.Id, "Type", "", "Required"));
            }
            else if (!UnitContact.AllowedTypes.Contains(this.Type.ToLower()))
            {
                errors.Add(new RuleViolation(this.Id, "Type", this.Type, "Must be one of: " + string.Join(", ", UnitContact.AllowedTypes)));
            }

            if (string.IsNullOrEmpty(this.Value))
            {
                errors.Add(new RuleViolation(this.Id, "Value", "", "Required"));
            }

            string dummy;

            if (!UnitContact.TryParse(this.Type, this.Value, true, out dummy))
            {
                errors.Add(new RuleViolation(this.Id, "Value", this.Value, string.Format("'{0}' is not in valid form", this.Value)));
            }

            return(errors.Count == 0);
        }
Exemple #2
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!UnitContact.AllowedTypes.Contains((this.Type ?? "*").ToLower()))
            {
                yield return(new ValidationResult("Must be one of: " + string.Join(", ", UnitContact.AllowedTypes), new[] { "Type" }));
            }

            string dummy;

            if (!UnitContact.TryParse(this.Type, this.Value, true, out dummy))
            {
                yield return(new ValidationResult(string.Format("'{0}' is not in valid form", this.Value), new[] { "Value" }));
            }
        }