public ResultEntity deleteExercise(int?exerciseId) { ResultEntity resultEntity = new ResultEntity(); if (exerciseId != null) { Exercise exercise = ExerciseApi.findByExerciseId(exerciseId); if (exercise != null) { ExerciseApi.delete(exercise.exerciseId); resultEntity.setState(1); resultEntity.setMessage("习题删除成功!"); } else { resultEntity.setMessage("未找到对应习题!"); resultEntity.setState(0); } } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }
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); }
public ResultEntity alterExercise(Exercise exercise) { ResultEntity resultEntity = new ResultEntity(); if (exercise != null) { //fragile Exercise exercise1 = ExerciseApi.findByExerciseId(exercise.exerciseId); if (exercise1 != null) { resultEntity.setData(ExerciseApi.insert(exercise)); resultEntity.setState(1); resultEntity.setMessage("习题修改成功!"); } else { resultEntity.setMessage("未找到对应习题!"); resultEntity.setState(0); } } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }
public ResultEntity answerOne(String answer, int?exerciseId, int?studentId) { ResultEntity resultEntity = new ResultEntity(); StudentExerciseScore studentExerciseScore = new StudentExerciseScore(studentId, exerciseId, answer, 0.ToString()); studentExerciseScore.corrected = 0; Exercise exercise = ExerciseApi.findByExerciseId(exerciseId); if (studentExerciseScore != null) { if (exercise.exerciseType % 3 != 0) { if (answer.Equals(exercise.exerciseAnswer)) { studentExerciseScore.corrected = 1; studentExerciseScore.exerciseScore = exercise.exercisePoint.ToString(); } } resultEntity.setData(StudentExerciseScoreApi.insert(studentExerciseScore)); if (resultEntity.getData() != null) { resultEntity.setState(1); resultEntity.setMessage("答题成功 !"); } else { resultEntity.setMessage("答题失败!"); resultEntity.setState(0); } } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }