public async Task <IActionResult> GetUser(string id) { var userFromRepo = await _repo.GetUserAsync(id); var user = _mapper.Map <UserToReturnDto>(userFromRepo); user.Roles = await _userManager.GetRolesAsync(userFromRepo); return(Ok(user)); }
public async Task <IActionResult> AddQuestion(QuestionToCreateDto questionToCreate) { var newquestion = _mapper.Map <Question>(questionToCreate); newquestion.Category = await _repo.GetCategoryAsync(questionToCreate.CategoryId); newquestion.QuestionBy = await _repo.GetUserAsync(questionToCreate.QuestionerId); _repo.Add(newquestion); if (await _repo.SaveAll()) { return(Ok(newquestion)); } throw new Exception("Question failed to add"); }
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"); }
public async Task <IActionResult> AddComment(CommentToCreateDto commentToCreate) { var comment = _mapper.Map <Comment>(commentToCreate); comment.article = await _repo.GetArticleAsync(commentToCreate.ArticleId); comment.Commenter = await _repo.GetUserAsync(commentToCreate.CommenterId); _repo.Add(comment); if (await _repo.SaveAll()) { return(Ok(comment)); } throw new Exception("Comment failed to post"); }
public async Task <IActionResult> AddArticle(ArticleToCreateDto articleToCreate) { var newArticle = _mapper.Map <Article>(articleToCreate); newArticle.Category = await _repo.GetCategoryAsync(articleToCreate.CategoryId); newArticle.Writer = await _repo.GetUserAsync(articleToCreate.WriterId); _repo.Add(newArticle); if (await _repo.SaveAll()) { return(Ok(newArticle)); } throw new Exception("Article failed to add"); }