I have a following problem: I'm moving the part of controller
of my system in the part of edit registers and it does the following verification, if I type an already existing code, it displays a alert .
ModelState.AddModelError("UserNotFound",
"Este Paciente já está cadastrado!: ");
And I wanted the alert to inform you of the patient ID that was registered with the one that made the following change.
ModelState.AddModelError("UserNotFound",
"Este Paciente já está cadastrado!: " + obj.CadastroId);
Only when I use obj.CadastroId
it is displaying the Patient ID I'm editing. In short, when the alert appears, display the Patient ID that has already been registered with that data.
Can anyone help me with this? I left on this link the method I'm using in controller
.
Repository:
public bool pacienteExiste(string numero_protuario)
{
Cadastro cadastro = Db.Cadastros
.FirstOrDefault(c => c.pront == numero_protuario);
return cadastro != null;
}
Service:
public bool pacienteExiste(string numero_protuario)
{
return _cadastroRepository.pacienteExiste(numero_protuario);
}
Controller:
[HttpPost]
public ActionResult EditarCadastro(Cadastro obj)
{
if (_cadastroService.pacienteExiste(obj.pront))
{
ModelState.AddModelError("UserNotFound",
"Este Paciente já está cadastrado!: " + obj.CadastroId);
return View(obj);
}
if ((obj.pront != null) || (obj.inpac != null) || (obj.dtnasc != null))
{
_cadastroService.Update(obj);
}
else
{
return RedirectToAction("Index", "Cadastro");
}
return RedirectToAction("Index", "Cadastro");
}