public Question GetFromDisplayHash(int id)
        {
            var question = new Question();
            question.Id = 1;
            question.QuestionText = "What does the fox says?";
            question.Answers = new List<Answer>();
            question.Answers.Add(new Answer() { Id = 1, AnswerText = "Foo" });
            question.Answers.Add(new Answer() { Id = 2, AnswerText = "Bar" });
            question.Answers.Add(new Answer() { Id = 4, AnswerText = "Baz" });
            question.Answers.Add(new Answer() { Id = 7, AnswerText = "Bak", IsCorrect = true });
            question.DisplayHash = 123;
            question.AdminHash = 123;

            return question;
        }
        public Question Add(Question q)
        {
            var question = _db.Questions.Add(q);
            foreach (var answer in question.Answers)
            {
                answer.QuestionId = question.Id;
                _db.Answers.Add(answer);
            }

            byte[] hashBytes = q.QuestionUniqueId.ToByteArray();

            question.DisplayHash = BitConverter.ToUInt16(hashBytes, 0);
            question.AdminHash = BitConverter.ToUInt16(hashBytes, 8);

            _db.SaveChanges();
            return question;
        }
예제 #3
0
        public Question(Question question)
        {
            Id = question.Id;
            QuestionText = question.QuestionText;
            AdminHash = question.AdminHash;
            DisplayHash = question.DisplayHash;
            QuestionUniqueId = question.QuestionUniqueId;

            if (question.Answers != null && question.Answers.Count != 0)
            {
                Answers = new List<Answer>();
                foreach (var item in question.Answers)
                {
                    Answers.Add(new Answer()
                    {
                        AnswerText = item.AnswerText,
                        Id = item.Id,
                        IsCorrect = item.IsCorrect,
                        QuestionId = item.QuestionId
                    });
                }
            }
        }
 public Question GenerateNewQuestion()
 {
     var q = new Question();
     q.Answers = new List<Answer>();
     return GetFromDisplayHash(9);
 }
 public Question Add(Question q)
 {
     q.Id = 5;
     return q;
 }
예제 #6
0
 public ActionResult New(Question q)
 {
     var added = _repository.Add(q);
     return RedirectToAction("Created", "Question", new { id = added.DisplayHash });
 }