public ActionResult CreateForParticipant(int participantId) { var isAdmin = EntityFetcher.FetchUserAdminStatus(Methods.GetUsernameFromCookie(HttpContext)); ViewBag.isAdmin = isAdmin; if (isAdmin == true) { var enrollment = new CreateEnrollmentVm { ParticipantId = participantId }; try { ViewBag.ParticipantName = EntityFetcher.FetchParticipantWithId(participantId).Name; enrollment.CoursesList = EntityFetcher.FetchCoursesNotEnrolled(participantId); } catch (DataException) { return(RedirectToAction("Index", "Home")); } return(View(enrollment)); } return(RedirectToAction("Login", "Home")); }
public static void CreateEnrollment(CreateEnrollmentVm enrollment) { using (var db = new SchedulerEntities()) { var dbEnrollment = new Entrollments { Course_Fk = enrollment.CourseId, Person_Fk = enrollment.ParticipantId }; db.Entrollments.Add(dbEnrollment); db.SaveChanges(); } }
public ActionResult CreateForParticipant(CreateEnrollmentVm enrollment) { var isAdmin = EntityFetcher.FetchUserAdminStatus(Methods.GetUsernameFromCookie(HttpContext)); ViewBag.isAdmin = isAdmin; if (isAdmin == true) { try { EntityModifier.CreateEnrollment(enrollment); } catch (DbEntityValidationException) { ModelState.AddModelError("CourseId", "Something went wrong, this course likely no longer exists."); return(View(enrollment)); } return(RedirectToAction("PersonEnrollments", new { personId = enrollment.ParticipantId })); } return(RedirectToAction("Login", "Home")); }