Example #1
0
 public override ValidationResult Validate(string propertyName, object value, HttpMethod method, ref bool isValidated)
 {
     if (this.Method != null)
     {
         var result = TfValidationResult.FieldRequired(propertyName, value);
         if (this.Method.ToList().Contains(method))
         {
             if (result != null)
             {
                 isValidated = true;
                 return(result);
             }
         }
     }
     else
     {
         var result = TfValidationResult.FieldRequired(propertyName, value);
         if (result != null)
         {
             isValidated = true;
             return(result);
         }
     }
     return(null);
 }
Example #2
0
        public override IEnumerable <ValidationResult> Validate()
        {
            yield return(TfValidationResult.FieldRequired(nameof(this.Key), this.Key));

            if (this.Accesses.Count == 0)
            {
                yield return(TfValidationResult.Compose("Unauthorized"));
            }
        }
Example #3
0
        private void ValidateProperties(dynamic model, ref Dictionary <string, object> validationDictionary)
        {
            if (model == null)
            {
                return;
            }

            foreach (var property in model.GetType().GetProperties())
            {
                if (property.PropertyType.GetConstructor(Type.EmptyTypes) != null &&
                    !property.PropertyType.GetType().IsAbstract)
                {
                    this.ValidateProperties(property.GetValue(model), ref validationDictionary);
                }

                var isValidated = false;
                foreach (var attribute in property.GetCustomAttributes(false))
                {
                    if (isValidated == true)
                    {
                        break;
                    }

                    var value = property.GetValue(model);

                    if (attribute is RequireInputAttribute)
                    {
                        var result = TfValidationResult.FieldRequired(property.Name, value);
                        if (result != null)
                        {
                            this.AddModelErrors(property.Name, result, ref validationDictionary);
                            isValidated = true;
                        }
                    }

                    if (attribute is ValidateInputAttribute && value != null)
                    {
                        var validateInputAttribute = attribute as ValidateInputAttribute;
                        var result = TfValidationResult.ValidateInput(validateInputAttribute.InputType, value, property.Name);
                        if (result != null)
                        {
                            this.AddModelErrors(property.Name, result, ref validationDictionary);
                            isValidated = true;
                        }
                    }
                }
            }
        }