Click or drag to resize

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 validation by validate class

  1. 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.

    C#
    [CustomValidation(typeof(Validation.Address), "ValidateName")]
    public string Name { get; set; }
  2. Validataion class (example: Address) has validtaion method.

    C#
    /// <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;
    }