2
I need help from you, I created two classes within my Controller, where I can remove a user from one page and send to another.
As if deleting but not erasing from the database.
I created a variable in my database called Removed where I think it would be best to work, when Removed for = 1 it transfers this user to another page, which in this case would be as if I were deleting the user from that page
follows the code
Inside the Controller
public ActionResult ExcluirCadastro(int id = 0)
{
if (!Cookies.Exists("hid")) {
return RedirectToAction("Index", "Login", new { area = "Entrar" });
}
var hospitalId = int.Parse(Cookies.GetCookie("hid"));
if (id <= 0 || hospitalId <= 0) {
return RedirectToAction("Index");
}
var excluirCadastro = _cadastroService.GetByPatientId(id, hospitalId);
if (excluirCadastro != null && excluirCadastro.HospitalId == hospitalId)
{
return View(excluirCadastro);
}
return RedirectToAction("Index");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DeletarPacientes(int cadastroId)
{
var cadastro = _cadastroService.GetbyId(cadastroId);
cadastro.Removido = !cadastro.Removido;
_cadastroService.Update(cadastro);
TempData["sucesso"] = "Paciente excluído com sucesso!";
return RedirectToAction("Index");
}
Page Excluircadastro.cshtml
<h3>Você tem certeza que deseja deletar este Paciente?</h3>
<dl class="dl-horizontal">
<dt>
<a style="color: #000000"><b>Nome</b></a>
</dt>
<dd>
@Html.DisplayFor(model => model.inpac)
</dd>
<dt>
<a style="color: #000000"><b>Data Nascimento</b></a>
</dt>
<dd>
@Html.DisplayFor(model => model.dtnasc)
</dd>
<dt>
<a style="color: #000000"><b>Código prontuário</b></a>
</dt>
<dd>
@Html.DisplayFor(model => model.pront)
</dd>
</dl>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<input type="hidden" name="cadastroId" value="@Model.CadastroId" />
<div class="form-actions no-color">
<button type="submit" class="btn btn-danger">Deletar</button> |
@Html.ActionLink("Voltar à Lista", "Index")
</div>
}
when I click the Delete button, it keeps entering this if
var excluirCadastro = _cadastroService.GetByPatientId(id, hospitalId);
if (excluirCadastro != null && excluirCadastro.HospitalId == hospitalId)
{
return View(excluirCadastro);
}
as much as when I enter the page and as much as when I click on delete, it is always entering this if, someone could help me?
I wanted that when I clicked on delete he would send this patient to a page set by me and update the variable Removed to 1.
and the class I created Deletarpacient I’m not getting into it
worked, thank you very much!
– Leonardo Macedo