0
I have the following problem: I am touching the part of controller
of my system on the part of editing registrations and it does the following check, if I enter an existing code, it displays a alert.
ModelState.AddModelError("UserNotFound",
"Este Paciente já está cadastrado!: ");
And I wanted it to be time to display the alert to let him know what the ID of patient that was registered with the data that I made the following change.
ModelState.AddModelError("UserNotFound",
"Este Paciente já está cadastrado!: " + obj.CadastroId);
Only when I use the obj.CadastroId
he is exhibiting the ID of patient I am editing. In short, when the alert appears, display the ID of patient that has already been registered with that data.
Could someone help me with this? , I left on this link the method I’m using on 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");
}
Why not put the code right here? In fact, also put the method code
_cadastroService.pacienteExiste
– Jéf Bueno
@jbueno public bool patientExiste(string numero_protuario) { Registration = Db.Cadastros.Firstordefault(c => c.pront == numero_protuario); Return registration != null; }
– Leonardo Macedo
Client at [Edit] and put the code in the question.
– Jéf Bueno
@jbueno put there, but I can’t edit to make visible
– Leonardo Macedo
Select the code and click Ctrl + k
– Jéf Bueno
@jbueno Pronto!
– Leonardo Macedo