Example #1
0
        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));
        }
Example #2
0
        // TODO update database - make spam, helpful, & unhelpful its own table with foreign keys QuestionId/AnswerId & accoundId
        // to check that the user hasn't already done that for that Question/Answer
        // rn a user can keep increase the counts forever

        // update spam count
        // email sys admin if a question or answer reaches spam limit
        // TODO go back to database and
        public PostedQuestion IncreaseQuestionSpamCount(int questionId, int accountId)
        {
            PostedQuestion question = _questionServices.GetPostedQuestion(questionId);

            // Validate
            if (accountId == question.AccountId)
            {
                throw new InvalidAccountException("User cannot mark their own question as spam");
            }

            question = _questionServices.IncreaseQuestionSpamCount(questionId);
            if (question.SpamCount == _spamLimit)
            {
                //               // call service to email admin because question reached spam limit
            }
            return(question);
        }
 public Task VoteQuestion(PostedQuestion question)
 {
     //ensure that the vote is registered for that question
     return(Task.CompletedTask);
 }