Ejemplo n.º 1
0
        internal Question GetById(int id)
        {
            Question data = _repo.GetById(id);

            if (data == null)
            {
                throw new Exception("Invalid Id");
            }
            return(data);
        }
Ejemplo n.º 2
0
        // Create/Update/Delete methods

        public async Task <Answer> CreateAnswerAsync(Answer answer, string userId)
        {
            var question = await _questionsRepository.GetById(answer.QuestionId);

            if (question == null)
            {
                return(null);
            }

            var access = await _quizzesRepository.HaveWriteAccessToQuiz(userId, question.QuizId);

            if (!access)
            {
                return(null);
            }

            var creationTime = CurrentTime;

            answer.CreationTime = creationTime;

            var version = new AnswerVersion {
                CreationTime = creationTime,
                Value        = answer.Value,
                IsCorrect    = answer.IsCorrect
            };

            answer.Versions.Add(version);
            answer.FlatVersionProps();

            await _answersRepository.Create(answer);

            var result = await Context.SaveChangesAsync() > 0;

            return(result ? answer : null);
        }
Ejemplo n.º 3
0
        public virtual Question GetQuestion(ViewQuestion viewQuestion)
        {
            Question mappedQuestion = _questionsRepository.GetById(viewQuestion.Id);

            mappedQuestion.SourceCode = viewQuestion.SourceCode;
            return(mappedQuestion);
        }
Ejemplo n.º 4
0
        public void GetById_WhenQuestionNotExists_ReturnsNull()
        {
            var questionsRepository = new QuestionsRepository();
            var gotQuestion         = questionsRepository.GetById(9999);

            Assert.IsNull(gotQuestion);
        }
Ejemplo n.º 5
0
        public void GetById_WhenQuestionNotExists_ReturnsNull()
        {
            var questionsRepository = new QuestionsRepository();
            var gotQuestion = questionsRepository.GetById(9999);

            Assert.IsNull(gotQuestion);
        }
Ejemplo n.º 6
0
        // Read methods

        public async Task <IList <Answer> > GetQuestionAnswersAsync(long questionId, string userId, long?maxVersionTime = null)
        {
            var question = await _questionsRepository.GetById(questionId);

            var access = await _quizzesRepository.HaveReadAccessToQuizAsync(userId, question.QuizId);

            if (!access)
            {
                return(null);
            }

            return(await _answersRepository
                   .GetAllByQuestionId(questionId, maxVersionTime)
                   .Include(a => a.Versions)
                   .Select(a => a.FlatVersionProps(maxVersionTime))
                   .ToListAsync());
        }
Ejemplo n.º 7
0
        public void GetById_WhenQuestionExists_ReturnsTheQuestion()
        {
            var stubQuestion = new Question();

            var questionsRepository = new QuestionsRepository {stubQuestion};
            var gotQuestion = questionsRepository.GetById(stubQuestion.Id);

            Assert.AreEqual(stubQuestion,gotQuestion);
        }
Ejemplo n.º 8
0
        public void GetById_WhenQuestionExists_ReturnsTheQuestion()
        {
            var stubQuestion = new Question();

            var questionsRepository = new QuestionsRepository {
                stubQuestion
            };
            var gotQuestion = questionsRepository.GetById(stubQuestion.Id);

            Assert.AreEqual(stubQuestion, gotQuestion);
        }
Ejemplo n.º 9
0
        public Question GetById(string id)
        {
            var question = _repo.GetById(id);

            return(question);
        }
Ejemplo n.º 10
0
 public Question GetById(int Id)
 {
     return(_repo.GetById(Id));
 }
 private void AssertVotesOnQuestion(int exectedVotes, Question question)
 {
     question = QuestionsRepository.GetById(question.Id);
     Assert.AreEqual(exectedVotes, question.Votes);
 }
Ejemplo n.º 12
0
        public ActionResult Resolve(int id)
        {
            Question question = _questionsRepository.GetById(id);

            return(View(_viewQuestionMapper.GetViewQuestion(question)));
        }