Data Validation Class |
The project's has two classes:
a data class with declaration of fields and
a validataion class with methods of validate (stroed in folder Validation).
Using: System.ComponentModel.DataAnnotations
Data class's at field name declares the attribute CustomValidation.
Example parameter: typeof(Validation.Address) declaration the validation class Address in folder Validation.
Example parameter: ValidateName declaration the method name in validataion class.
Class based of SOWIData.DataStandard as System.Data.Entity.DBContext.
[CustomValidation(typeof(Validation.Address), "ValidateName")] public string Name { get; set; }
Validataion class (example: Address) has validtaion method.
/// <summary> /// Validate has more as one character. Has no character then validation message. /// </summary> /// <param name="pName">Field value to validation</param> /// <returns>Validataion result</returns> public static ValidationResult ValidateName(string pName) { if (pName.Length == 0) { return new ValidationResult("Kein Name angegeben!"); } return ValidationResult.Success; }