// GET: Enrolments/Create
 public ActionResult Create(int? courseId, int? studentId)
 {
     var model = new EnrolmentCreateModel();
     model.StudentId = studentId;
     model.CourseId = courseId;
     model.Courses = Mapper.Map<IEnumerable<SelectListItem>>(Context.Courses).OrderBy(x => x.Text);
     model.Students = Mapper.Map<IEnumerable<SelectListItem>>(Context.Students).OrderBy(x => x.Text);
     return View(model);
 }
        public ActionResult Create(EnrolmentCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var course = Context.Courses.Find(model.CourseId);
            var student = Context.Students.Find(model.StudentId);
            
            var enrolment = new Enrolment(course, student);
            enrolment.Grade = model.Grade;
            course.Enrolments.Add(enrolment);
            Context.SaveChanges();

            return RedirectToAction("details", "enrolments", new { id = enrolment.Id });
        }