Exemplo n.º 1
0
 public ActionResult Enroll(CourseEnrollmentModel model)
 {
     if (ModelState.IsValid)
     {
         var course = ConsumerContext.Courses.Find(model.CourseId);
         var user = UserManager.FindById(model.UserId);
         if (model.Enrolled)
         {
             course.EnrolledUsers.Remove(user);
         }
         else
         {
             course.EnrolledUsers.Add(user);
         }
         ConsumerContext.SaveChanges();
     }
     return RedirectToAction("Details", new { id = model.CourseId });
 }
Exemplo n.º 2
0
 public ActionResult Enroll(int courseId)
 {
     var course = ConsumerContext.Courses.Find(courseId);
     var enrolled = course.EnrolledUsers.Count(u => u.Id == User.Identity.GetUserId()) > 0;
     var model = new CourseEnrollmentModel
     {
         CourseId = courseId,
         Enrolled = enrolled,
         UserId = User.Identity.GetUserId()
     };
     return PartialView("_EnrollPartial", model);
 }