How to set custom validation that when Entry.state
== EntityState.Added
is true the below code would work!
Custom Validation Code:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
class UniqueEmailAddress : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
this.email = (string)value;
using (G9EntityDataBaseClass oEntity = new G9EntityDataBaseClass())
{
if (oEntity.User.Where(u => u.email == email).Count() == 0)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult(ErrorMessageString);
}
}
}
}
use :
[CustomValidation.UniqueEmailAddress]
public string email { set; get; }
i need ((NOT)EntityState.Added):
if (Entry.state != EntityState.Added){
return ValidationResult.Success;
}
From where should i bring Entry.state