Beispiel #1
0
        public static ContactInfoSubType GetSubTypes(string type)
        {
            ContactInfoSubType subType = new ContactInfoSubType()
            {
                ValueLabel = "Value", SubTypes = new string[0], ValidationString = ""
            };

            switch (type.ToLower())
            {
            case "phone":
                subType.SubTypes   = new string[] { "cell", "home", "work", "pager" };
                subType.ValueLabel = "Number";
                break;

            case "im":
                subType.SubTypes   = new string[] { "messenger", "aim", "yahoo", "google", "twitter" };
                subType.ValueLabel = "Address";
                break;

            case "email":
                subType.ValueLabel = "Address";
                break;

            case "hamcall":
                subType.ValueLabel = "Call Sign";
                break;
            }

            return(subType);
        }
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(this.Type))
            {
                yield return(new ValidationResult("Required", new[] { "Type" }));
            }
            else if (!PersonContact.AllowedTypes.Contains(this.Type.ToLower()))
            {
                yield return(new ValidationResult("Must be one of: " + string.Join(", ", PersonContact.AllowedTypes), new[] { "Type" }));
            }

            ContactInfoSubType subtypes = PersonContact.GetSubTypes(this.Type);

            if (subtypes.SubTypes.Length == 0 && !string.IsNullOrEmpty(this.Subtype))
            {
                yield return(new ValidationResult("SubType can't be specified for type '" + this.Type + "'", new[] { "SubType" }));
            }
            else if (subtypes.SubTypes.Length > 0 && !subtypes.SubTypes.Contains(this.Subtype))
            {
                yield return(new ValidationResult("SubType must be one of: " + string.Join(", ", subtypes.SubTypes), new[] { "SubType" }));
            }

            string dummy;

            if (string.IsNullOrEmpty(this.Value))
            {
                yield return(new ValidationResult("Required", new[] { "Value" }));
            }
            else if (!PersonContact.TryParse(this.Type, this.Subtype, this.Value, true, out dummy))
            {
                yield return(new ValidationResult(string.Format("'{0}' is not in valid form", this.Value), new[] { "Value" }));
            }
        }
Beispiel #3
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 (!PersonContact.AllowedTypes.Contains(this.Type.ToLower()))
            {
                errors.Add(new RuleViolation(this.Id, "Type", this.Type, "Must be one of: " + string.Join(", ", PersonContact.AllowedTypes)));
            }

            ContactInfoSubType subtypes = PersonContact.GetSubTypes(this.Type);

            if (subtypes.SubTypes.Length == 0 && !string.IsNullOrEmpty(this.Subtype))
            {
                errors.Add(new RuleViolation(this.Id, "SubType", this.Subtype, "SubType can't be specified for type '" + this.Type + "'"));
            }
            else if (subtypes.SubTypes.Length > 0 && !subtypes.SubTypes.Contains(this.Subtype))
            {
                errors.Add(new RuleViolation(this.Id, "SubType", this.Subtype, "SubType must be one of: " + string.Join(", ", subtypes.SubTypes)));
            }

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

            string dummy;

            if (!PersonContact.TryParse(this.Type, this.Subtype, 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);
        }
        public static ContactInfoSubType GetSubTypes(string type)
        {
            ContactInfoSubType subType = new ContactInfoSubType() { ValueLabel = "Value", SubTypes = new string[0], ValidationString = "" };

              switch (type.ToLower())
              {
            case "phone":
              subType.SubTypes = new string[] { "cell", "home", "work", "pager" };
              subType.ValueLabel = "Number";
              break;
            case "im":
              subType.SubTypes = new string[] { "messenger", "aim", "yahoo", "google", "twitter" };
              subType.ValueLabel = "Address";
              break;
            case "email":
              subType.ValueLabel = "Address";
              break;
            case "hamcall":
              subType.ValueLabel = "Call Sign";
              break;
              }

              return subType;
        }