I need your help, I created two classes inside my Controller, where I can pull a user from one page and send it to another.
As if you were deleting but not deleting from the database.
I created a variable in my database called Removed where I think it would be better to work when Removed is = 1 it transfers this user to another page , which in this case would be like I was deleting the user from that page
follow 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");
}
ExcludeCadastro.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 on the Delete button, it always goes into this if
var excluirCadastro = _cadastroService.GetByPatientId(id, hospitalId);
if (excluirCadastro != null && excluirCadastro.HospitalId == hospitalId)
{
return View(excluirCadastro);
}
Both when I enter the page and both when I click delete, it is always entering this if, could someone help me?
Home
I wanted it when I clicked on deleting it it would send this patient to a page defined by me and would update the Removed variable to 1.
and the class I created Deleting Patients I'm not getting into it