1
Guys, I have a little problem with my application, which is a course manager. The problem is that "student" has to enroll in some course, only I’m not able to make the student’s association to the course. On my registration screen I have a button "enrollment", where, the student clicks and this button should associate the "student" to that particular course, in addition to associate, this button also makes the decrease of vacancies of that course according to what students will enroll.
I’m trying to do it like this
Meu Controller
public ActionResult Inscricao(int? id)
{
using (var scope = new TransactionScope())
{
// Aqui pegaria o aluno logado.
// E aqui é onde tenho que fazer a associação do aluno ao curso.
Curso curso = new Curso();
//Tentei fazer assim, mas não consegui
curso = db.Cursos.Include(a => a.Aluno).AsNoTracking().FirstOrDefault(c => c.Id == id);
curso.Qtd_Vagas--;
db.Entry(curso).State = EntityState.Modified;
db.SaveChanges();
scope.Complete();
}
return View("Inscricao", db.Cursos.ToList());
}
Related: http://answall.com/questions/67387/listagem-no-asp-net-mvc/67474
– Leonel Sanches da Silva