Exemplo n.º 1
0
        public void SaveResult(FullQuestionEntity question, string nickname)
        {
            var user    = uow.UserRepository.GetUserByNickname(nickname)?.ToBllUser();
            var answers = uow.AnswerRepository.GetAllAnswersByIdQuestion(question.Id)?.ToList().Select(x => x.ToBllAnswer()).ToList();

            bool trueAnswer = true;
            int  i          = 0;

            foreach (var requestAnswer in question.Answers)
            {
                if (requestAnswer.IsTrue != answers[i].IsTrue)
                {
                    trueAnswer = false;
                }
                i++;
            }

            var result = new ResultEntity
            {
                QuestionId   = question.Id,
                UserId       = user.Id,
                PassedTime   = DateTime.Now,
                IsTrueAnswer = trueAnswer
            };

            uow.ResultRepository.Create(result.ToDalResult());
            uow.Commit();
        }
Exemplo n.º 2
0
 public static FullQuestionViewModel ToMvcQuestion(this FullQuestionEntity questionModel)
 {
     return(new FullQuestionViewModel
     {
         Id = questionModel.Id,
         QuestionContent = questionModel.QuestionContent,
         QuantityPoint = questionModel.QuantityPoint,
         TestId = questionModel.TestId,
         Answers = questionModel.Answers.Select(x => x.ToMvcAnswer())
     });
 }
Exemplo n.º 3
0
        public void DeleteQuestion(FullQuestionEntity questionEntity)
        {
            questionEntity.Answers.ToList().ForEach(x => uow.AnswerRepository.Delete(x.ToDalAnswer()));
            var question = new QuestionEntity
            {
                Id = questionEntity.Id,
                QuestionContent = questionEntity.QuestionContent,
                QuantityPoint   = questionEntity.QuantityPoint,
                TestId          = questionEntity.TestId
            };

            uow.QuestionRepository.Delete(question.ToDalQuestion());
            uow.Commit();
        }
Exemplo n.º 4
0
 public void UpdateQuestion(FullQuestionEntity questionEntity)
 {
     if (questionEntity != null)
     {
         var simpleQuestion = new QuestionEntity
         {
             Id = questionEntity.Id,
             QuestionContent = questionEntity.QuestionContent,
             QuantityPoint   = questionEntity.QuantityPoint,
             TestId          = questionEntity.TestId
         };
         uow.QuestionRepository.Update(simpleQuestion.ToDalQuestion());
         uow.AnswerRepository.DeleteAllByIdQuestion(questionEntity.Id);
         questionEntity.Answers.ToList().ForEach(x => uow.AnswerRepository.Create(x.ToDalAnswer()));
         uow.Commit();
     }
 }
Exemplo n.º 5
0
        public void CreateQuestion(FullQuestionEntity questionEntity)
        {
            var simpleQuestion = new QuestionEntity
            {
                Id = questionEntity.Id,
                QuestionContent = questionEntity.QuestionContent,
                QuantityPoint   = questionEntity.QuantityPoint,
                TestId          = questionEntity.TestId
            };

            uow.QuestionRepository.Create(simpleQuestion.ToDalQuestion());
            uow.Commit();
            var listAnswers     = questionEntity.Answers.ToList();
            var currentQuestion = uow.QuestionRepository.GetQuestionByParams(questionEntity.TestId, questionEntity.QuestionContent)?.ToBllQuestion();

            if (currentQuestion != null)
            {
                listAnswers.ForEach(x => { x.QuestionId = currentQuestion.Id; uow.AnswerRepository.Create(x.ToDalAnswer()); });
            }
            uow.Commit();
        }