Exemplo n.º 1
0
 // ---------------------------------------------------------------------------------------------
 public static void CopyValues(TestQuestionDTO source, test_question target)
 {
     target.id              = source.id;
     target.module_id       = source.module_id;
     target.position        = source.position;
     target.question_answer = source.question_answer;
 }
Exemplo n.º 2
0
 // PUBLIC
 // =============================================================================================
 public static TestQuestionDTO GetDTO(test_question entity)
 {
     return(new TestQuestionDTO {
         id = entity.id,
         module_id = entity.module_id,
         position = entity.position,
         question_answer = entity.question_answer
     });
 }
Exemplo n.º 3
0
 public static Test_questionDTO Test_questionToDTO(test_question tq)
 {
     return(new Test_questionDTO()
     {
         question_id = tq.question_id,
         question_test_id = tq.question_test_id,
         test_id = tq.test_id
     });
 }
Exemplo n.º 4
0
        // PUBLIC
        // =============================================================================================
        public TestQuestionDTO UpsertQuestion(TestQuestionDTO questionReceived)
        {
            var           id = questionReceived.id;
            test_question question;

            if (id == 0)
            {
                question = new test_question();
                TestQuestionMapper.CopyValues(questionReceived, question);
                _questionRepository.Add(question);
            }
            else
            {
                question = _questionRepository.Get(id);
                _questionRepository.SetNewValues(questionReceived, question);
            }

            return(TestQuestionMapper.GetDTO(question));
        }
Exemplo n.º 5
0
        // ---------------------------------------------------------------------------------------------
        public List <TestQuestionAnswDTO> VerifyClosedTest(TestQuestionAnswDTO[] answers, int userId)
        {
            var answersList = answers.ToList();
            var user        = _userService.GetUserEntity(userId);

            string questionDataStr;
            int    correctAnswer;
            bool   prevResult;

            foreach (var ans in answersList)
            {
                // Ustalenie indeksu poprawnej odpowiedzi dla tego pytania
                test_question question = GetQuestionEntity(ans.question_id);
                questionDataStr = question.question_answer;
                correctAnswer   = Int32.Parse(questionDataStr.Split('^')[1]);


                // Ustawienie :
                // - prawidłowości wyniku na liście odpowiedzi użytkownika,
                // - odpowiedzi dla frontu - użytkownik odpowiedział prawidłowo lub nie.
                bool result;
                int  lastAnswer = ans.answer_id;
                if (lastAnswer == correctAnswer)
                {
                    result        = true;
                    ans.answer_id = 1;
                }
                else
                {
                    result        = false;
                    ans.answer_id = 0;
                }


                // Domyślny poprzedni wynik odpowiedzi na to pytanie
                prevResult = false;

                // Pobranie pytania z listy pytań, na które użytkownik już odpowiadał ...
                user_question answeredQuestion = user.user_question.ToList()
                                                 .Where(q => q.question_id == ans.question_id)
                                                 .FirstOrDefault();

                if (answeredQuestion != null)
                {
                    prevResult = answeredQuestion.last_result;
                }

                // ... lub dodanie nowego pytania do listy pytań, na które użytkownik odpowiedział
                else
                {
                    prevResult = false;

                    answeredQuestion = new user_question()
                    {
                        user_id      = userId,
                        question_id  = ans.question_id,
                        first_result = result
                    };
                    user.user_question.Add(answeredQuestion);
                }

                answeredQuestion.last_result = result;
                answeredQuestion.last_answer = lastAnswer;


                // przeliczenie życia, ochrony i awansu sapera
                if (!prevResult || !answeredQuestion.last_result)
                {
                    CalculateGame(ref user, GameItem.QUESTION, result, Lottery.NO_LOTTERY);
                }
            }

            _userService.SaveChanges();

            return(answersList);
        }