Пример #1
0
        public async Task <IActionResult> PostAnswer(AnswerToPostDto answerToPostDto)
        {
            try
            {
                var ans = await _questionRepository.PostAnswer(answerToPostDto);

                return(Ok(ans));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public async Task <Answer> PostAnswer(AnswerToPostDto answerToPostDto)
        {
            var qobj = await GetQuestionById(answerToPostDto.QuestionId);

            var user = await _context.Users.FirstOrDefaultAsync(m => m.Id == answerToPostDto.UserId);

            var ans = new Answer {
                Question = qobj, Solution = answerToPostDto.Solution, User = user
            };
            var a = _context.Answers.Add(ans);

            if (await _context.SaveChangesAsync() > 0)
            {
                return(ans);
            }
            return(null);
        }