Ejemplo n.º 1
0
        public void AddQuestion(string userId, QuestionModel questionModel)
        {
            var questionId = Guid.NewGuid().ToString();

            var question = new QuestionEntity()
            {
                Question     = questionModel.Question,
                Options      = String.Join(", ", questionModel.Options),
                QuestionType = (int)questionModel.QuestionType,
                QuestionId   = questionId,
                UserId       = userId
            };

            UnitOfWork.QuestionRepository.Insert(question);
            UnitOfWork.Commit();

            var questionCount = UserProgressService.GetAnsweredQuestionCount(userId);
            var userProgress  = UserProgressRepository.GetCurrentProgress(userId);

            userProgress.Question = question;
            userProgress.QuestionNumber++;

            UnitOfWork.UserProgressRepository.Update(userProgress);
            UnitOfWork.Commit();
        }
Ejemplo n.º 2
0
        public void AddAnswer(string userId, string answer)
        {
            var currentQuestion = UserProgressRepository.GetCurrentQuestion(userId);
            var question        = QuestionRepository.GetQuestion(currentQuestion.QuestionId);

            question.Response = answer;
            UnitOfWork.QuestionRepository.Update(question);
            UnitOfWork.Commit();
        }
Ejemplo n.º 3
0
        public void UpdatePartNumber(string userId, int newPartNumber)
        {
            var userProgress = UserProgressRepository.GetCurrentProgress(userId);

            userProgress.PartNumber     = newPartNumber;
            userProgress.QuestionNumber = 0;
            userProgress.Question       = null;

            UnitOfWork.UserProgressRepository.Update(userProgress);
            UnitOfWork.Commit();
        }
Ejemplo n.º 4
0
        public QuestionModel GetCurrentQuestion(string userId)
        {
            var currentQuestion = UserProgressRepository.GetCurrentQuestion(userId);

            if (currentQuestion == null)
            {
                return(null);
            }
            var question = QuestionRepository.GetQuestion(currentQuestion.QuestionId);

            return(Mapper.Map <QuestionModel>(question));
        }
Ejemplo n.º 5
0
        public QuestionModel GetNextQuestion(string userId)
        {
            var questionCount = UserProgressRepository.GetQuestionCount(userId);
            var currentPart   = UserProgressRepository.GetCurrentPartNumber(userId);

            if (currentPart == 1 && questionCount > 9)
            {
                return(null);
            }
            if (currentPart == 2 && questionCount > 2)
            {
                return(null);
            }

            var           userInformation = UserRepository.GetUserInformation(userId);
            QuestionModel question;

            if (currentPart == 1)
            {
                if (SurveySettings.ControlQuestions.Contains(questionCount))
                {
                    question = new QuestionModel("Two letters will appear on the screen. Your task is to examine the options and then pick one of the letters. There is no correct answer for any quesiton.", GenerateOptionsForPartOne(userInformation.Name, Enums.QuestionType.CONTROL), Enums.QuestionType.CONTROL);
                }
                else
                {
                    question = new QuestionModel("Two letters will appear on the screen. Your task is to examine the options and then pick one of the letters. There is no correct answer for any quesiton.", GenerateOptionsForPartOne(userInformation.Name, Enums.QuestionType.EXPERIMENTAL), Enums.QuestionType.EXPERIMENTAL);
                }
            }
            else
            {
                question = GenerateOptionsForPartTwo(questionCount, userInformation.BirthDate);
            }

            AddQuestion(userId, question);

            return(question);
        }
Ejemplo n.º 6
0
 public int GetAnsweredQuestionCount(string userId)
 {
     return(UserProgressRepository.GetQuestionCount(userId));
 }
Ejemplo n.º 7
0
 public int GetCurrentPartNumber(string userId)
 {
     return(UserProgressRepository.GetCurrentPartNumber(userId));
 }