public async Task <IActionResult> GetQuestion(int id) { var question = await _repo.GetQuestionAsync(id); var questionToReturn = _mapper.Map <QuestionToReturnDto>(question); return(Ok(questionToReturn)); }
public async Task <IActionResult> AddAnswer(AnswerToCreateDto answerToCreate) { var answer = _mapper.Map <Answer>(answerToCreate); answer.AnsweredBy = await _repo.GetUserAsync(answerToCreate.AnswererId); answer.Question = await _repo.GetQuestionAsync(answerToCreate.QuestionId); _repo.Add(answer); if (await _repo.SaveAll()) { return(Ok(answer)); } throw new Exception("answer failed to add"); }