示例#1
0
        public ResultEntity findOneExerice(int?exerciseId)
        {
            ResultEntity resultEntity = new ResultEntity();

            if (exerciseId != null)
            {
                Exercise exercise = ExerciseApi.findByExerciseId(exerciseId);
                if (exercise != null)
                {
                    if (exercise.exerciseType % 3 != 0)
                    {
                        List <ExerciseChoice> exerciseChoices = ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exerciseId);
                        resultEntity.setData(new ExerciseSet(exercise, exerciseChoices));
                    }
                    else
                    {
                        resultEntity.setData(new ExerciseSet(exercise));
                    }
                    resultEntity.setState(1);
                    resultEntity.setMessage("搜索习题成功!");
                }
                else
                {
                    resultEntity.setMessage("搜索习题失败!");
                    resultEntity.setState(0);
                }
            }
            else
            {
                resultEntity.setMessage("传入参数为空!");
                resultEntity.setState(0);
            }
            return(resultEntity);
        }
示例#2
0
        public ResultEntity viewSomeAnswer(int?chapterId, int?studentId, String type)
        {
            ResultEntity resultEntity = new ResultEntity();

            if (chapterId != null && studentId != null)
            {
                List <ExerciseSet> exerciseSets = new List <ExerciseSet>();
                int type1 = 0;
                int type2 = 0;
                int type3 = 0;
                if (type.Equals("preview"))
                {
                    type1 = 1;
                    type2 = 3;
                    type3 = 2;
                }
                else
                {
                    type1 = 4;
                    type2 = 6;
                    type3 = 5;
                }
                List <Exercise> exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type1);
                foreach (Exercise exercise in exercises)
                {
                    if (StudentExerciseScoreApi.existsByExerciseIdAndStudentId(exercise.exerciseId, studentId) == false)
                    {
                        resultEntity.setMessage("学生未答题!");
                        resultEntity.setState(0);
                        return(resultEntity);
                    }
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId), StudentExerciseScoreApi.findByExerciseIdAndStudentId(exercise.exerciseId, studentId).studentAnswer));
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type3);
                foreach (Exercise exercise in exercises)
                {
                    if (StudentExerciseScoreApi.existsByExerciseIdAndStudentId(exercise.exerciseId, studentId) == false)
                    {
                        resultEntity.setMessage("学生未答题!");
                        resultEntity.setState(0);
                        return(resultEntity);
                    }
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId), StudentExerciseScoreApi.findByExerciseIdAndStudentId(exercise.exerciseId, studentId).studentAnswer));
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type2);
                foreach (Exercise exercise in exercises)
                {
                    if (StudentExerciseScoreApi.existsByExerciseIdAndStudentId(exercise.exerciseId, studentId) == false)
                    {
                        resultEntity.setMessage("学生未答题!");
                        resultEntity.setState(0);
                        return(resultEntity);
                    }
                    exerciseSets.Add(new ExerciseSet(exercise, StudentExerciseScoreApi.findByExerciseIdAndStudentId(exercise.exerciseId, studentId).studentAnswer));
                }
                List <int?> scores = exerciseScore(studentId, chapterId, type);
                resultEntity.setData(new ExerciseSetsDetails(exerciseSets, scores));
                if (resultEntity.getData() != null)
                {
                    resultEntity.setState(1);
                    resultEntity.setMessage("查看成功!");
                }
                else
                {
                    resultEntity.setMessage("查看失败!");
                    resultEntity.setState(0);
                }
            }
            else
            {
                resultEntity.setMessage("传入参数为空!");
                resultEntity.setState(0);
            }
            return(resultEntity);
        }
示例#3
0
        public ResultEntity viewExercise(int?chapterId, String type)
        {
            ResultEntity resultEntity = new ResultEntity();

            if (chapterId != null)
            {
                List <ExerciseSet> exerciseSets = new List <ExerciseSet>();
                int type1 = 0;
                int type2 = 0;
                int type3 = 0;
                if (type.Equals("preview"))
                {
                    type1 = 1;
                    type3 = 2;
                    type2 = 3;
                }
                else
                {
                    type1 = 4;
                    type3 = 5;
                    type2 = 6;
                }
                List <Exercise> exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type1);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId)));
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type3);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId)));
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type2);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise));
                }
                resultEntity.setData(exerciseSets);
                if (resultEntity.getData() != null)
                {
                    if (type.Equals("preview"))
                    {
                        //fragile
                        if (ChapterContentApi.getByID(chapterId).exerciseVisible_1 != null && ChapterContentApi.getByID(chapterId).exerciseVisible_1)
                        {
                            DateTime now = DateTime.Now;
                            if (ChapterContentApi.getByID(chapterId).exerciseDeadline_1 != null && now > ChapterContentApi.getByID(chapterId).exerciseDeadline_1)
                            {
                                resultEntity.setState(4);
                                resultEntity.setMessage("习题已过deadline!");
                            }
                            else
                            {
                                resultEntity.setState(1);
                                resultEntity.setMessage("查看成功!");
                            }
                        }
                        else
                        {
                            resultEntity.setState(2);
                            resultEntity.setMessage("习题当前设置为不可见!");
                        }
                    }
                    else
                    {
                        if (ChapterContentApi.getByID(chapterId).exerciseDeadline_2 != null && ChapterContentApi.getByID(chapterId).exerciseVisible_2)
                        {
                            DateTime now = DateTime.Now;
                            if (ChapterContentApi.getByID(chapterId).exerciseDeadline_2 != null && now > ChapterContentApi.getByID(chapterId).exerciseDeadline_2)
                            {
                                resultEntity.setState(4);
                                resultEntity.setMessage("习题已过deadline!");
                            }
                            else
                            {
                                resultEntity.setState(1);
                                resultEntity.setMessage("查看成功!");
                            }
                        }
                        else
                        {
                            resultEntity.setState(2);
                            resultEntity.setMessage("习题当前设置为不可见!");
                        }
                    }
                }
                else
                {
                    resultEntity.setMessage("无题目!");
                    resultEntity.setState(3);
                }
            }
            else
            {
                resultEntity.setMessage("传入参数为空!");
                resultEntity.setState(0);
            }
            return(resultEntity);
        }
示例#4
0
        public ResultEntity answerAll(List <String> answers, int?studentId, int?chapterId, String type, String comment, int?rate)
        {
            ResultEntity resultEntity = new ResultEntity();

            if (answers != null && type != null && chapterId != null && studentId != null)
            {
                List <ExerciseSet> exerciseSets = new List <ExerciseSet>();
                int type1 = 0;
                int type2 = 0;
                int type3 = 0;
                if (type.Equals("preview"))
                {
                    type1 = 1;
                    type3 = 2;
                    type2 = 3;
                }
                else
                {
                    type1 = 4;
                    type3 = 5;
                    type2 = 6;
                }
                List <int?>     exerciseIds = new List <int?>();
                List <Exercise> exercises   = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type1);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId)));
                    exerciseIds.Add(exercise.exerciseId);
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type3);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId)));
                    exerciseIds.Add(exercise.exerciseId);
                }
                exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type2);
                foreach (Exercise exercise in exercises)
                {
                    exerciseSets.Add(new ExerciseSet(exercise));
                }
                for (int i = 0; i < answers.Count; i++)
                {
                    answerOne(answers[i], exerciseSets[i].getExercise().exerciseId, studentId);
                }
                int score = 0;
                foreach (int?exerciseId in exerciseIds)
                {
                    score += int.Parse(StudentExerciseScoreApi.findByExerciseIdAndStudentId(exerciseId, studentId).exerciseScore);
                }
                StudentChapter studentChapter;
                if (!StudentChapterApi.existsByChapterIDAndStudentID(chapterId, studentId))
                {
                    studentChapter           = new StudentChapter();
                    studentChapter.chapterID = chapterId;
                    studentChapter.studentID = studentId;
                    StudentChapterApi.insert(studentChapter);
                }
                if (!type.Equals("preview"))
                {
                    studentChapter              = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId);
                    studentChapter.rate         = rate;
                    studentChapter.comment      = comment;
                    studentChapter.totalScore_2 = score;
                    studentChapter.scored_2     = 0;
                    StudentChapterApi.insert(studentChapter);
                    //LaterImplementation
                    //new NLPUtil().setCommentNLPRate(comment, chapterId, studentId);
                }
                else
                {
                    studentChapter = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId);
                    studentChapter.totalScore_1 = score;
                    studentChapter.scored_1     = 0;
                    StudentChapterApi.insert(studentChapter);
                }
                resultEntity.setState(1);
                resultEntity.setMessage("答题成功 !");
            }
            else
            {
                resultEntity.setMessage("传入参数有空值!");
                resultEntity.setState(0);
            }
            return(resultEntity);
        }