示例#1
0
        public static async Task <bool> SendToReviewAndUpdateScore(UserExerciseSubmission submissionNoTracking,
                                                                   IWebCourseManager courseManager, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, IVisitsRepo visitsRepo, MetricSender metricSender)
        {
            var userId   = submissionNoTracking.UserId;
            var courseId = submissionNoTracking.CourseId;
            var course   = await courseManager.GetCourseAsync(courseId);

            var exerciseSlide = course.FindSlideById(submissionNoTracking.SlideId, true) as ExerciseSlide;             // SlideId проверен в вызывающем методе

            if (exerciseSlide == null)
            {
                return(false);
            }
            var exerciseMetricId                = GetExerciseMetricId(courseId, exerciseSlide);
            var automaticCheckingNoTracking     = submissionNoTracking.AutomaticChecking;
            var isProhibitedUserToSendForReview = await slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId);

            var sendToReview = exerciseSlide.Scoring.RequireReview &&
                               submissionNoTracking.AutomaticCheckingIsRightAnswer &&
                               !isProhibitedUserToSendForReview &&
                               await groupsRepo.IsManualCheckingEnabledForUserAsync(course, userId);

            if (sendToReview)
            {
                await slideCheckingsRepo.RemoveWaitingManualCheckings <ManualExerciseChecking>(courseId, exerciseSlide.Id, userId, false);

                await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submissionNoTracking.Id);

                await visitsRepo.MarkVisitsAsWithManualChecking(courseId, exerciseSlide.Id, userId);

                metricSender.SendCount($"exercise.{exerciseMetricId}.sent_to_review");
                metricSender.SendCount("exercise.sent_to_review");
            }

            await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide, userId);

            if (automaticCheckingNoTracking != null)
            {
                var verdictForMetric = automaticCheckingNoTracking.GetVerdict().Replace(" ", "");
                metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}");
            }

            return(sendToReview);
        }