I have an application that manages Courses and I have the following problem, student makes your enrollment in courses >, but when the student accesses the page where they list the courses they are enrolled in, this list is also listing other students' courses , and not only or the student who is logged in .
I tried to do this
My Action
of controller Curso
public ActionResult MeusCursos()
{
Aluno aluno = db.Alunos.FirstOrDefault(a => a.Usuario == User.Identity.Name);
if (aluno != null)
return View("MeusCursos", db.Cursos.ToList());
return View();
}
Post
[HttpPost]
public ActionResult MeusCursos(int id)
{
Aluno aluno = db.Alunos.FirstOrDefault(a => a.Usuario == User.Identity.Name);
if (aluno != null)
return View("MeusCursos", db.Cursos.ToList());
var curso = db.Cursos.FirstOrDefault(c => c.Id == id);
if (curso == null)
return View("MeusCursos");
return View(db.Cursos.ToList());
}