Exemplo n.º 1
0
        public List <int> SaveStudentTotalScore(StoreScore storeScore)
        {
            try
            {
                List <int> results          = new List <int>();
                Exam       exam             = examDal.GetExamByExamId(storeScore.ExamId);
                List <int> isCorrectAnswers = examDal.SelectStudentAnswerScore(storeScore.UserId, storeScore.ExamId);

                int correctNum = 0;
                for (int i = 0; i < isCorrectAnswers.Count; i++)
                {
                    if (isCorrectAnswers[i] == 1)
                    {
                        correctNum++;
                    }
                }

                storeScore.Score = correctNum * exam.SingleScore;

                if (storeScore.Score >= exam.PassScore)
                {
                    storeScore.Operation = "Pass";
                }

                else if (storeScore.Score < exam.PassScore)
                {
                    storeScore.Operation = "No pass";
                }
                examDal.SaveStudentTotalScore(storeScore);
                results.Add(storeScore.Score);
                results.Add(correctNum);
                return(results);
            }
            catch (SqlException sqlException)
            {
                log.Error(sqlException.StackTrace);
                throw new FaultException <DBException>(new DBException(), Constants.ServerError);
            }
        }