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());
        }
 public void Add(ResponseGoal responseGoal)
 {
     _responseGoalRepository.Create(responseGoal);
 }
예제 #3
0
        public ActionResult Index1(Guid key, int QuestionnaireID, ResponseViewModel[] responses, ResponseGoal goal)
        {
            if (ModelState.IsValid)
            {
                Student student = _studentService.GetStudentByKey(key);
                if (student != null)
                {
                    foreach (var item in responses)
                    {
                        _responseService.Add(new Response
                        {
                            Question_ID = item.Question_ID,
                            Response_ID = item.Response_ID,
                            Student_ID  = student.ID
                        });
                    }
                    _responseGoalService.Add(new ResponseGoal {
                        Student_ID    = student.ID,
                        First_Goal_ID = goal.First_Goal_ID,
                        Why           = goal.Why
                    });
                    _unitOfWork.Commit();
                    Question next = _questionService.NextQuestionnaire(QuestionnaireID);

                    if (next == null)
                    {
                        return(RedirectToAction("Finish", new { key = key }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", new { ID = next.ID, key = key }));
                    }
                }
            }
            ViewBag.Questionnaire = _questionService.GetQuestionnaire(QuestionnaireID);
            return(View());
        }