private TocModel CreateGuestTocModel(Course course, int slideIndex) { var visibleUnits = unitsRepo.GetVisibleUnits(course.Id, User); var builder = new TocModelBuilder( s => Url.Action("Slide", "Course", new { courseId = course.Id, slideIndex = s.Index }), s => 0, course, slideIndex); builder.IsInstructor = false; builder.IsVisited = s => false; builder.IsUnitVisible = visibleUnits.Contains; var toc = builder.CreateTocModel(); toc.NextUnitTime = unitsRepo.GetNextUnitPublishTime(course.Id); return(toc); }
private TocModel CreateGuestTocModel(Course course, Guid?currentSlideId) { var visibleUnits = unitsRepo.GetVisibleUnits(course, User); var builder = new TocModelBuilder( s => Url.RouteUrl("Course.SlideById", new { courseId = course.Id, slideId = s.Url }), s => 0, s => 0, (u, g) => 0, course, currentSlideId) { IsInstructor = false, IsVisited = s => false, IsUnitVisible = visibleUnits.Contains, IsSlideHidden = s => s is QuizSlide && ((QuizSlide)s).ManualChecking }; var toc = builder.CreateTocModel(); toc.NextUnitTime = unitsRepo.GetNextUnitPublishTime(course.Id); return(toc); }
public async Task <ActionResult> Slide(string courseId, int slideIndex = -1) { if (string.IsNullOrWhiteSpace(courseId)) { return(RedirectToAction("Index", "Home")); } var visibleUnits = unitsRepo.GetVisibleUnits(courseId, User); var isGuest = !User.Identity.IsAuthenticated; var model = isGuest ? CreateGuestCoursePageModel(courseId, slideIndex, visibleUnits) : await CreateCoursePageModel(courseId, slideIndex, visibleUnits); if (!visibleUnits.Contains(model.Slide.Info.UnitName)) { throw new Exception("Slide is hidden " + slideIndex); } return(View(model)); }
public async Task <ActionResult> SlideById(string courseId, string slideId = "", int?checkQueueItemId = null, int?version = null, int autoplay = 0) { if (slideId.Contains("_")) { slideId = slideId.Substring(slideId.LastIndexOf('_') + 1); } var groupsIds = Request.GetMultipleValuesFromQueryString("group"); if (!Guid.TryParse(slideId, out var slideGuid)) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(courseId)) { if (string.IsNullOrWhiteSpace(slideId)) { return(RedirectToAction("Index", "Home")); } return(RedirectToSlideById(slideGuid)); } var course = courseManager.FindCourse(courseId); if (course == null) { return(HttpNotFound()); } var visibleUnits = unitsRepo.GetVisibleUnits(course, User); var isGuest = !User.Identity.IsAuthenticated; var slide = slideGuid == Guid.Empty ? GetInitialSlideForStartup(courseId, visibleUnits) : course.FindSlideById(slideGuid); if (slide == null) { return(HttpNotFound()); } AbstractManualSlideChecking queueItem = null; var isManualCheckingReadonly = false; if (User.HasAccessFor(courseId, CourseRole.Instructor) && checkQueueItemId != null) { if (slide is QuizSlide) { queueItem = slideCheckingsRepo.FindManualCheckingById <ManualQuizChecking>(checkQueueItemId.Value); } if (slide is ExerciseSlide) { queueItem = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(checkQueueItemId.Value); } if (queueItem == null) { /* It's possible when checking has not been fully checked, lock has been released, but after it user re-send his solution and we removed old waiting checking */ var fakeQueueItem = slide is QuizSlide ? (AbstractManualSlideChecking) new ManualQuizChecking() : new ManualExerciseChecking(); return(RedirectToAction("CheckingQueue", "Admin", new { courseId = courseId, message = "checking_removed" })); } } var model = isGuest ? CreateGuestCoursePageModel(course, slide, autoplay > 0) : await CreateCoursePageModel(course, slide, queueItem, version, groupsIds, autoplay > 0, isManualCheckingReadonly); if (!string.IsNullOrEmpty(Request.QueryString["error"])) { model.Error = Request.QueryString["error"]; } if (!visibleUnits.Contains(model.Slide.Info.Unit)) { return(HttpNotFound("Slide is hidden " + slideGuid)); } return(View("Slide", model)); }
public async Task <ActionResult> SlideById(string courseId, string slideId = "", int?checkQueueItemId = null, int?version = null, int autoplay = 0) { if (slideId.Contains("_")) { slideId = slideId.Substring(slideId.LastIndexOf('_') + 1); } var groupsIds = Request.GetMultipleValues("group"); Guid slideGuid; if (!Guid.TryParse(slideId, out slideGuid)) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(courseId)) { if (string.IsNullOrWhiteSpace(slideId)) { return(RedirectToAction("Index", "Home")); } return(RedirectToSlideById(slideGuid)); } var course = courseManager.FindCourse(courseId); if (course == null) { return(HttpNotFound()); } var visibleUnits = unitsRepo.GetVisibleUnits(course, User); var isGuest = !User.Identity.IsAuthenticated; var slide = slideGuid == Guid.Empty ? GetInitialSlideForStartup(courseId, course, visibleUnits) : course.FindSlideById(slideGuid); if (slide == null) { return(HttpNotFound()); } AbstractManualSlideChecking queueItem = null; var isManualCheckingReadonly = false; if (User.HasAccessFor(courseId, CourseRole.Instructor) && checkQueueItemId != null) { if (slide is QuizSlide) { queueItem = slideCheckingsRepo.FindManualCheckingById <ManualQuizChecking>(checkQueueItemId.Value); } if (slide is ExerciseSlide) { queueItem = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(checkQueueItemId.Value); } if (queueItem == null) { return(HttpNotFound()); } /* If lock time is finished */ if (!queueItem.IsLockedBy(User.Identity) && queueItem.HasLastLockedBy(User.Identity)) { return(RedirectToAction(GetAdminQueueActionName(queueItem), "Admin", new { CourseId = courseId, group = string.Join(",", groupsIds), done = queueItem.IsChecked, message = "time_is_over", })); } /* If it's not locked then lock them! */ if (!queueItem.IsLocked) { return(RedirectToAction(GetAdminCheckActionName(queueItem), "Admin", new { CourseId = courseId, group = string.Join(",", groupsIds), id = queueItem.Id, recheck = true })); } if (queueItem.IsLocked && !queueItem.IsLockedBy(User.Identity)) { isManualCheckingReadonly = true; } } var model = isGuest ? CreateGuestCoursePageModel(course, slide, autoplay > 0) : await CreateCoursePageModel(course, slide, queueItem, version, groupsIds, autoplay > 0, isManualCheckingReadonly); if (!string.IsNullOrEmpty(Request.QueryString["error"])) { model.Error = Request.QueryString["error"]; } if (!visibleUnits.Contains(model.Slide.Info.Unit)) { return(HttpNotFound("Slide is hidden " + slideGuid)); } return(View("Slide", model)); }