public async Task <IEnumerable <Module> > GetCourseModulesAsync(int courseId)
        {
            // We only need assessments and quizzes cause only they can be graded
            var courseModules = await _moodleCoursesService.GetCourseModulesAsync(courseId);

            var quizAndAssesmentCourses = courseModules.Where(cm =>
                                                              cm.ModName == nameof(TaskTypes.assign) || cm.ModName == nameof(TaskTypes.quiz));

            foreach (var quizAndAssesmentCourse in quizAndAssesmentCourses)
            {
                var originalModule = await _moduleService.GetModuleAsync(quizAndAssesmentCourse.Id);

                quizAndAssesmentCourse.Course = courseId;
                quizAndAssesmentCourse.Grade  = originalModule.MaxGrade;
            }

            return(_mapper.Map <IEnumerable <Module> >(quizAndAssesmentCourses));
        }
예제 #2
0
        public async Task <TaskResult> GetTaskResult(int moduleId, int userId)
        {
            var module = await _moduleService.GetModuleAsync(moduleId);

            try
            {
                var gradeForTask = module.Type switch
                {
                    nameof(TaskTypes.assign) =>
                    await _moodleGradeService.GetAssignmentGradeAsync(module.TypeId, userId),
                    nameof(TaskTypes.quiz) => await _moodleGradeService.GetQuizGradeAsync(module.TypeId, userId),
                    _ => null
                };
                return(gradeForTask != null?_mapper.Map <TaskResult>(gradeForTask) : null);
            }
            catch (Exception e)
            {
                return(null);
            }
        }