I have a user registry where I use the remote validation in the data annotation to check if the user that is being registered already exists, my problem is in editing, how I am changing and using the same object the system thinks I am registering a new user and informs that I can not register because the registration informed already exists.
How do I make sure that when I'm editing the registry, it does not check for duplicity?
My template
[DisplayName("E-mail")]
[Required(ErrorMessage = "Favor informar o E-mail do usuário")]
[Remote("Unico", "Usuario", ErrorMessage = "Esse e-mail já existe no sistema")]
[RegularExpression(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}", ErrorMessage = "Favor informe um e-mail válido")]
public string email{ get; set; }
And here I have the remote validation function
public ActionResult Unico(string email)
{
try
{
int idUsuario = 123;//Usuário/ADM de teste
Models.user = bd.users.SingleOrDefault(s => s.email == email && s.idUsuario == idUsuario);
bool retorno = false;
if (c == null)
{
retorno = true;
}
return Json(retorno, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}