Beispiel #1
0
        private ExerciseBlockData CreateExerciseBlockData(Course course, Slide slide, UserExerciseSubmission submission, bool onlyAccepted, string currentUserId)
        {
            var userId = submission?.UserId ?? currentUserId;
            var visit  = visitsRepo.FindVisit(course.Id, slide.Id, userId);

            var solution = submission?.SolutionCode.Text;

            if (string.IsNullOrEmpty(solution))
            {
                /* I.e. after clicking on `Try again` button solution is empty. Let's try to show last sent submission */
                var lastSubmission = userSolutionsRepo.GetAllSubmissionsByUser(course.Id, slide.Id, currentUserId).OrderByDescending(s => s.Timestamp).FirstOrDefault();
                solution = lastSubmission?.SolutionCode.Text;
            }

            var submissionReviews = submission?.GetAllReviews();

            var hasUncheckedReview = submission?.ManualCheckings.Any(c => !c.IsChecked) ?? false;
            var hasCheckedReview   = submission?.ManualCheckings.Any(c => c.IsChecked) ?? false;
            var reviewState        = hasCheckedReview ? ExerciseReviewState.Reviewed :
                                     hasUncheckedReview ? ExerciseReviewState.WaitingForReview :
                                     ExerciseReviewState.NotReviewed;

            var submissions = onlyAccepted ?
                              userSolutionsRepo.GetAllAcceptedSubmissionsByUser(course.Id, slide.Id, userId) :
                              userSolutionsRepo.GetAllSubmissionsByUser(course.Id, slide.Id, userId);
            var topUserReviewComments       = slideCheckingsRepo.GetTopUserReviewComments(course.Id, slide.Id, currentUserId, 20);
            var topOtherUsersReviewComments = slideCheckingsRepo.GetTopOtherUsersReviewComments(course.Id, slide.Id, currentUserId, 10, topUserReviewComments);

            return(new ExerciseBlockData(course.Id, (ExerciseSlide)slide, visit?.IsSkipped ?? false, solution)
            {
                Url = Url,
                Reviews = submissionReviews?.ToList() ?? new List <ExerciseCodeReview>(),
                ReviewState = reviewState,
                IsGuest = string.IsNullOrEmpty(currentUserId),
                SubmissionSelectedByUser = submission,
                Submissions = submissions.ToList(),
                TopUserReviewComments = topUserReviewComments,
                TopOtherUsersReviewComments = topOtherUsersReviewComments,
                CurrentUser = usersRepo.FindUserById(User.Identity.GetUserId())
            });
        }
Beispiel #2
0
        public ActionResult Submission(string courseId, Guid slideId, string userId = null, int?submissionId = null, int?manualCheckingId = null, bool isLti = false, bool showOutput = false, bool instructorView = false, bool onlyAccepted = true)
        {
            if (!User.HasAccessFor(courseId, CourseRole.Instructor))
            {
                instructorView = false;
            }

            var currentUserId = userId ?? (User.Identity.IsAuthenticated ? User.Identity.GetUserId() : "");
            UserExerciseSubmission submission = null;

            if (submissionId.HasValue && submissionId.Value > 0)
            {
                submission = userSolutionsRepo.FindSubmissionById(submissionId.Value);
                if (submission == null)
                {
                    return(HttpNotFound());
                }
                if (!string.Equals(courseId, submission.CourseId, StringComparison.OrdinalIgnoreCase))
                {
                    return(HttpNotFound());
                }
                if (slideId != submission.SlideId)
                {
                    return(HttpNotFound());
                }
                if (!User.HasAccessFor(courseId, CourseRole.Instructor) && submission.UserId != currentUserId)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }
            else if (!submissionId.HasValue && !manualCheckingId.HasValue)
            {
                submission = GetExerciseSubmissionShownByDefault(courseId, slideId, currentUserId, instructorView);
            }

            var course = courseManager.GetCourse(courseId);
            var slide  = course.FindSlideById(slideId);

            if (slide == null)
            {
                return(HttpNotFound());
            }

            ManualExerciseChecking manualChecking = null;

            if (User.HasAccessFor(courseId, CourseRole.Instructor) && manualCheckingId.HasValue)
            {
                manualChecking = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(manualCheckingId.Value);
            }
            if (manualChecking != null && !submissionId.HasValue)
            {
                submission = manualChecking.Submission;
            }

            var model = CreateExerciseBlockData(course, slide, submission, onlyAccepted, currentUserId);

            model.IsLti = isLti;
            model.ShowOutputImmediately = showOutput;
            model.InstructorView        = instructorView;
            model.ShowOnlyAccepted      = onlyAccepted;
            if (manualChecking != null)
            {
                if (manualChecking.CourseId.EqualsIgnoreCase(courseId))
                {
                    model.ManualChecking = manualChecking;
                    model.Reviews        = submission?.GetAllReviews() ?? new List <ExerciseCodeReview>();
                }
            }

            return(PartialView(model));
        }