public Answer PostAnswer(AnswerCreateRequestDTO a, int accountId) { //Validations Account answerer = _userManagementServices.FindById(accountId); PostedQuestion question = _questionServices.GetPostedQuestion(a.QuestionId); if (question.IsClosed) { throw new QuestionIsClosedException("Question is closed"); } if (answerer.Exp < question.ExpNeededToAnswer) { throw new NotEnoughExpException("User does not have enough Exp to answer"); } //Create Answer after passed in Answer is validated Answer answer = new Answer() { QuestionId = a.QuestionId, AccountId = accountId, Text = a.Text, }; //Post Answer return(_answerServices.PostAnswer(answer)); }
public IHttpActionResult PostAnswer([FromBody] AnswerCreateRequestDTO answerDTO) { List <string> requiredClaims = new List <string>() { }; authUserId = AuthorizeUser(requiredClaims); if (authUserId == 0) { return(Unauthorized()); } using (var _db = new DatabaseContext()) { DiscussionForumManager discussionForumManager = new DiscussionForumManager(_db); try { // TODO accountId should come from authorization and take out hard-coded value discussionForumManager.PostAnswer(answerDTO, authUserId); _db.SaveChanges(); return(Content(HttpStatusCode.OK, "Answer posted successfully")); } catch (QuestionIsClosedException ex) { return(Content(HttpStatusCode.Forbidden, ex.Message)); } catch (NotEnoughExpException ex) { // TODO BadRequest? return(Content(HttpStatusCode.BadRequest, ex.Message)); } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, ex.InnerException)); } } }