Ejemplo n.º 1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            Employee model = (Employee)validationContext.ObjectInstance;

            if (string.IsNullOrEmpty(model.Notes))
            {
                return(ValidationResult.Success);
            }
            var res = EmployeeValidator.ValidateProfanity(model.Notes);

            if (!res.isValid)
            {
                string s = "";
                for (int i = 0; i < res.errors.Count; i++)
                {
                    s += res.errors[i];
                    if (i != res.errors.Count - 1)
                    {
                        s += ", ";
                    }
                    else
                    {
                        s += " ";
                    }
                }
                return(new ValidationResult($"Disse ord er ikke tilladt: {s}"));
            }
            return(ValidationResult.Success);
        }