示例#1
0
        private async Task <IEnumerable <IApiSlideBlock> > RenderBlock(AbstractExerciseBlock b, SlideRenderContext context)
        {
            var submissions = await solutionsRepo
                              .GetAllSubmissionsByUser(context.CourseId, context.Slide.Id, context.UserId)
                              .Include(s => s.AutomaticChecking).ThenInclude(c => c.Output)
                              .Include(s => s.AutomaticChecking).ThenInclude(c => c.CompilationError)
                              .Include(s => s.AutomaticChecking).ThenInclude(c => c.DebugLogs)
                              .Include(s => s.SolutionCode)
                              .Include(s => s.Reviews).ThenInclude(c => c.Author)
                              .Include(s => s.ManualCheckings).ThenInclude(c => c.Reviews).ThenInclude(r => r.Author)
                              .ToListAsync();

            var codeReviewComments = await slideCheckingsRepo.GetExerciseCodeReviewComments(context.CourseId, context.Slide.Id, context.UserId);

            var isCourseAdmin = await courseRolesRepo.HasUserAccessToCourseAsync(context.UserId, context.CourseId, CourseRoleType.CourseAdmin);

            ExerciseAttemptsStatistics exerciseAttemptsStatistics = null;

            if (b.HasAutomaticChecking())
            {
                var exerciseUsersCount = await slideCheckingsRepo.GetExerciseUsersCount(context.CourseId, context.Slide.Id);

                var exerciseUsersWithRightAnswerCount = await slideCheckingsRepo.GetExerciseUsersWithRightAnswerCount(context.CourseId, context.Slide.Id);

                var lastSuccessAttemptDate = await slideCheckingsRepo.GetExerciseLastRightAnswerDate(context.CourseId, context.Slide.Id);

                exerciseAttemptsStatistics = new ExerciseAttemptsStatistics
                {
                    AttemptedUsersCount       = exerciseUsersCount,
                    UsersWithRightAnswerCount = exerciseUsersWithRightAnswerCount,
                    LastSuccessAttemptDate    = lastSuccessAttemptDate
                };
            }

            var exerciseSlideRendererContext = new ExerciseSlideRendererContext
            {
                Submissions        = submissions,
                CodeReviewComments = codeReviewComments,
                SlideFile          = context.Slide.Info.SlideFile,
                CanSeeCheckerLogs  = isCourseAdmin,
                AttemptsStatistics = exerciseAttemptsStatistics,
            };

            return(new[] { new ExerciseBlockResponse(b, exerciseSlideRendererContext) });
        }