-1
The Controller is always returning the error message, when the email is registered or not in the database.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Nome,Email,Senha")] Pessoas pessoas)
{
if (pessoas != null)
{
var verificaemail = db.Pessoas.Where(w => w.Email == "Email").FirstOrDefault();
if (verificaemail != null)
{
db.Pessoas.Add(pessoas);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
ModelState.AddModelError("", "E-mail já cadastrado");
return View();
}
}
else
{
return View(pessoas);
}
}
It is working, but with a however, is the opposite, when it was to give the error he register, and when it was to register is giving error. I guess my logic was wrong.
– Rodrigo Santos
I did it based on what you posted and what you can infer, if I give some more information I can try to improve
– Maniero
If I change if (person != null) to (person == null) the logic of the code makes more sense?
– Rodrigo Santos
I don’t think so, but I’d need to see more context.
– Maniero