public async Task <ActionResult <AnswerInfo> > GetAnswerAsync(long id) { var result = _answerServices.GetAnswer(id); long userId = (await _userManager.FindByIdAsync(_userManager.GetUserId(HttpContext.User))).UserId; if (result == null) { return(NotFound()); } result.Status = _answerActivityServices.LikeActivityStatus(userId, result.Id); return(result); }
public Answer MarkAsCorrectAnswer(int answerId, int accountId) { var answer = _answerServices.GetAnswer(answerId); var question = answer.PostedQuestion; var account = _userManagementServices.FindById(answer.AccountId); // Validations if (question.IsClosed) { throw new QuestionIsClosedException("Question is closed"); } if (question.AccountId != accountId) { throw new InvalidAccountException("User cannot mark an answer as correct on another user's question"); } answer = _answerServices.MarkAnswerAsCorrect(answerId); question = _questionServices.CloseQuestion(question.Id); account.Exp += _expGainCorrectAns; account = _userManagementServices.UpdateUser(account); return(answer); }