Change password Student

Asked

Viewed 325 times

1

In the student environment, they must change their password.

I created the code below but can’t get results in the bank. Someone notices something wrong?

[HttpPost]
public ActionResult AlterarSenha(CONSUL_CA_Aluno aluno)
{
    string cpf = System.Web.HttpContext.Current.User.Identity.Name;
    var bdAluno = CONSUL_CA_AlunoAplicacaoConstrutor.CONSUL_CA_AlunoAplicacaoEF();
    var alunoNovaSenha = bdAluno.ListarTodos().Where(x => x.Cpf == cpf).First();

    ViewData["aluno"] = aluno;
    ViewBag.Senha = aluno.Senha;
    bdAluno.Salvar(alunoNovaSenha);

    return View();
}
  • I think the first line can be reduced to string cpf = Page.User.Identity.Name (or just User.Identity.Name... I’m a little rusty).

  • Another thing... If the query does not bring results, there is a possibility that the CONSUL_CA_AlunoAplicacaoEF, or the method ListarTodos, is empty. We would need to see the code of these methods.

1 answer

1


Looks like you’re trying to save alunoNovaSenha without changing his password.

Whereas the correct password is on aluno, the code below should solve the problem:

alunoNovaSenha.Senha = aluno.Senha;
bdAluno.Salvar(alunoNovaSenha);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.