1
I have an application that manages Courses and I have the following problem, the pupil makes his enrollment in courses, only when the pupil access the page where lists the courses he is enrolled, this list is also listing the courses of other students, and not only the student who is logged.
I tried to do so
My Action
controller’s 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());
}
Apenar.
HttpGet
to request data query,HttpPost
to request addition/creation of data,HttpPut
to request data update andHttpDelete
to request data deletion.– Thiago Lunardi