using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace FirstSteps.Validation
{
    public class BlackListValidation: ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var str = value as string;
            var unwortListe = new List<string>();

            unwortListe.Add("Linux");
            unwortListe.Add("Unix");
            unwortListe.Add("iPhone");
            unwortListe.Add("Assembler");

            foreach(var wort in unwortListe) {
                
                if (str.Contains(wort))
                {
                    var member = new string[] { validationContext.MemberName };
                    var vr = new ValidationResult("Da ist ja ein Unwort drinnen", member);
                    return vr;
                }
            }

            return ValidationResult.Success;
        }
    }
}