Ejemplo n.º 1
0
 public QuestionController()
 {
     _unitOfWork                    = new UnitOfWork();
     _questionService               = new QuestionService(_unitOfWork);
     _responseService               = new ResponseService(_unitOfWork);
     _responseGoalService           = new ResponseGoalService(_unitOfWork);
     _responseImportanceSortService = new ResponseImportanceSortService(_unitOfWork);
     _resultService                 = new ResultService(_unitOfWork);
     _studentService                = new StudentService(_unitOfWork);
 }
        public Result_View CalculateResult(Student student, ResponseGoalService _responseGoalService, QuestionService _questionService)
        {
            bool haveResult = db.Result.Where(d => d.Student_ID == student.ID).Any();

            if (haveResult == false)
            {
                List <Question> list = _questionService.GetQuestionnaireList();

                ResponseGoal      goal = _responseGoalService.GetGoal(student);
                Q2ResultViewModel q2   = GetStudentQ2Result(student, list[1]);
                int q3 = GetStudentQ3Result(student, list[2]);
                Q4ResultViewModel q4             = GetStudentQ4Result(student, list[3]);
                int[]             importanceTop3 = ResponseImportanceSort(student);

                Result result = new Result()
                {
                    Student_ID       = student.ID,
                    Goal_ID          = goal.First_Goal_ID,
                    DISC_Number      = q2.Number,
                    D                = q2.D,
                    I                = q2.I,
                    S                = q2.S,
                    C                = q2.C,
                    Ability          = q3,
                    Horizontal_Score = q4.橫坐標,
                    Vertical_Score   = q4.縱坐標,
                    Top_1            = importanceTop3[0],
                    Top_2            = importanceTop3[1],
                    Top_3            = importanceTop3[2]
                };
                db.Result.Add(result);
                db.SaveChanges();
            }

            return(db.Result_View.Where(d => d.Student_ID == student.ID).FirstOrDefault());
        }