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 }); }
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(); }
public void GetQuestion() { var res = questionRepo.GetByIdAsync(1).Result; Assert.AreEqual("What is the price of DocumentDb?", res.message); }