// GET: Courses/Edit/courseId // returns edit view where a teacher can modify the course's data public ActionResult Edit(int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } // check if the user trying to access the course is a supervisor var supervisors = SupervisorHelper.GetSupervisorsForCourse(id); // if he isn't, then return him => denied if (!supervisors.Any(x => x.UserID == CurrentWebContext.CurrentUser.UserID)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } // create the viewmodel var viewModel = DetailedCourseVM.CreateDetailedCourseVMW(course, supervisors); ViewBag.CountOfPendingStudents = ParticipantHelper.GetCountOfPendingParticipants(id); return(View(viewModel)); }
public ActionResult Edit([Bind(Include = "CourseID,CourseName,CourseDescription,CreatorID, Supervisors, Participants, Lectures")] DetailedCourseVM model) { if (ModelState.IsValid) { var course = new Course() { CourseID = model.CourseID, CourseName = model.CourseName, CourseDescription = model.CourseDescription, CreatorID = model.CreatorID, Creator = model.Creator }; course.Update(); } return(RedirectToAction("Index", new { userId = CurrentWebContext.CurrentUser.UserID })); }
// GET: Courses/Details/courseId // returns details view with all related data depending on the logged in user public ActionResult Details(int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // cast nullable int int id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } DetailedCourseVM viewModel = null; // check if the current user is a student and setup accordingly the view model if (CurrentWebContext.CurrentUser.Type == "student") { ViewBag.IsParticipant = false; viewModel = new DetailedCourseVM(course); viewModel.Lectures = LectureHelper.GetLecturesForCourse(course.CourseID); // get the type of student for this course ViewBag.StatusOfStudent = CourseHelper.GetStudentStatusForCourse(CurrentWebContext.CurrentUser.UserID, course.CourseID); } // check if the current user is a teacher and create the view model for him if (CurrentWebContext.CurrentUser.Type == "teacher") { viewModel = DetailedCourseVM.CreateDetailedCourseVMW(course); ViewBag.CountOfPendingStudents = ParticipantHelper.GetCountOfPendingParticipants(id); } return(View(viewModel)); }