Exemple #1
0
        public static async Task <HashSet <Guid> > GetSolvedSlides(IUserSolutionsRepo solutionsRepo, IUserQuizzesRepo userQuizzesRepo, Course course, string userId)
        {
            var solvedSlides = await solutionsRepo.GetIdOfPassedSlides(course.Id, userId);

            solvedSlides.UnionWith(await userQuizzesRepo.GetPassedSlideIdsAsync(course.Id, userId));
            return(solvedSlides);
        }
        public async Task AddManualCheckingsForOldSolutionsAsync(string courseId, string userId)
        {
            log.Info($"Создаю ручные проверки для всех решения пользователя {userId} в курсе {courseId}");

            var course = await courseManager.GetCourseAsync(courseId);

            /* For exercises */
            var acceptedSubmissionsBySlide = userSolutionsRepo.GetAllAcceptedSubmissionsByUser(courseId, userId)
                                             .ToList()
                                             .GroupBy(s => s.SlideId)
                                             .ToDictionary(g => g.Key, g => g.ToList());

            foreach (var acceptedSubmissionsForSlide in acceptedSubmissionsBySlide.Values)
            {
                /* If exists at least one manual checking for at least one submissions on slide, then ignore this slide */
                if (!acceptedSubmissionsForSlide.Any(s => s.ManualCheckings.Any()))
                {
                    /* Otherwise found the latest accepted submission */
                    var lastSubmission = acceptedSubmissionsForSlide.OrderByDescending(s => s.Timestamp).First();

                    var slideId = lastSubmission.SlideId;
                    var slide   = course.FindSlideById(slideId, false) as ExerciseSlide;
                    if (slide == null || !slide.Scoring.RequireReview)
                    {
                        continue;
                    }

                    log.Info($"Создаю ручную проверку для решения {lastSubmission.Id}, слайд {slideId}");
                    await slideCheckingsRepo.AddManualExerciseChecking(courseId, slideId, userId, lastSubmission.Id).ConfigureAwait(false);

                    await visitsRepo.MarkVisitsAsWithManualChecking(courseId, slideId, userId).ConfigureAwait(false);
                }
            }

            /* For quizzes */
            var passedQuizzesIds = await userQuizzesRepo.GetPassedSlideIdsAsync(courseId, userId).ConfigureAwait(false);

            foreach (var quizSlideId in passedQuizzesIds)
            {
                var slide = course.FindSlideById(quizSlideId, false) as QuizSlide;
                if (slide == null || !slide.ManualChecking)
                {
                    continue;
                }
                if (!await userQuizzesRepo.IsWaitingForManualCheckAsync(courseId, quizSlideId, userId).ConfigureAwait(false))
                {
                    log.Info($"Создаю ручную проверку для теста {slide.Id}");
                    var submission = await userQuizzesRepo.FindLastUserSubmissionAsync(courseId, quizSlideId, userId).ConfigureAwait(false);

                    if (submission == null || submission.ManualChecking != null)
                    {
                        continue;
                    }
                    await slideCheckingsRepo.AddManualQuizChecking(submission, courseId, quizSlideId, userId).ConfigureAwait(false);

                    await visitsRepo.MarkVisitsAsWithManualChecking(courseId, quizSlideId, userId).ConfigureAwait(false);
                }
            }
        }