示例#1
0
        public async Task <IActionResult> Answer(string id, AnswerPostDto answerPostDto)
        {
            try
            {
                var qid      = new Guid(answerPostDto.QuestionId);
                var question = await _questionRepository.GetById(qid);

                var ans = new Answer
                {
                    Solution = answerPostDto.Solution,
                    UserId   = new Guid(id),
                    Vote     = 0
                };
                question.Answers = new List <Answer>();
                question.Answers.Add(ans);
                _questionRepository.Update(question);
                if (await _unitOfWork.Commit())
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
 public async Task <IActionResult> Answer(string id, AnswerPostDto answerPostDto)
 {
     try
     {
         var answer = _mapper.Map <Answer>(answerPostDto);
         answer.UserId = new Guid(id);
         _answerRepository.Add(answer);
         if (await _unitOfWork.Commit())
         {
             return(Ok());
         }
         return(BadRequest());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }