Exemplo n.º 1
0
        public override IEnumerable <ValidationResult> Validate()
        {
            if (this.File == null || this.File?.Length == 0)
            {
                yield return(TfValidationResult.Compose("RequiredField", nameof(this.File)));
            }
            else
            {
                switch (this.FileType)
                {
                case Mvc.FileType.Image:
                    if (this.File.ContentType != "image/gif" &&
                        this.File.ContentType != "image/jpeg" &&
                        this.File.ContentType != "image/png" &&
                        this.File.ContentType != "image/svg+xml")
                    {
                        yield return(TfValidationResult.Compose("InvalidInput", nameof(this.File), nameof(this.File)));
                    }
                    break;

                case Mvc.FileType.CSV:
                    if (this.File.ContentType != "text/csv")
                    {
                        yield return(TfValidationResult.Compose("InvalidInput", nameof(this.File), nameof(this.File)));
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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"));
            }
        }
Exemplo n.º 4
0
 public override IEnumerable <ValidationResult> Validate()
 {
     if (this.Handling)
     {
         this.Accesses.Entity.key    = this.Key;
         this.Accesses.Entity.secret = this.Secret;
         if (this.Accesses.Count == 0)
         {
             yield return(TfValidationResult.Compose("Unauthorized"));
         }
     }
 }
Exemplo n.º 5
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;
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
 public override ValidationResult Validate(string propertyName, object value, HttpMethod method, ref bool isValidated)
 {
     if (this.InputType.HasValue)
     {
         var result = TfValidationResult.Input(this.InputType.Value, value, propertyName);
         if (result != null)
         {
             isValidated = true;
             return(result);
         }
     }
     if (this.Length.HasValue)
     {
         var result = TfValidationResult.Length(this.Length.Value, value, propertyName);
         if (result != null)
         {
             isValidated = true;
             return(result);
         }
     }
     return(null);
 }