public async Task <OperationResult <question> > GetByIdAsync(int id)
        {
            question question = await questionRepo.GetByIdAsync(id);

            if (question != null)
            {
                return(new OperationResult <question>()
                {
                    Success = true, Message = Messages.QUESTION_SUCCESS, Result = question
                });
            }
            return(new OperationResult <question>()
            {
                Success = false, Message = Messages.QUESTION_NOT_EXIST
            });
        }
示例#2
0
        public async Task VoteQuestion(int questionId, bool isUpvote, int userId)
        {
            var question = await _questionRepository.GetByIdAsync(questionId);

            if (isUpvote)
            {
                question.Votes++;
            }
            else
            {
                question.Votes--;
            }

            await _userQuestionRepository.CreateAsync(new UserQuestion()
            {
                IsUpvote   = isUpvote,
                QuestionId = questionId,
                UserId     = userId
            });

            _questionRepository.Update(question);

            await _unitOfWork.Commit();
        }
示例#3
0
        public void GetQuestion()
        {
            var res = questionRepo.GetByIdAsync(1).Result;

            Assert.AreEqual("What is the price of DocumentDb?", res.message);
        }