/// <summary> /// This method does all the things necessary to handle a offensive answer given by a certain user /// --> Answer is added to bad_answers table /// </summary> /// <param name="newAnswerNonsenseCheck"></param> public static void ProcessOffensiveAnswer(NewAnswerOffenseCheck newAnswerOffenseCheck) { DBManager manager = new DBManager(true); /****/ String sqlSafeAnswer = ServerUtilities.UserInputToSQLSafe(newAnswerOffenseCheck.answer); /****/ // Add a reference to the answer in the bad_answer table StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO dbo.BadAnswers (bad_answer, question_id, answer_author_id) "); sb.Append($"VALUES ('{sqlSafeAnswer}', {newAnswerOffenseCheck.question_id}, '{newAnswerOffenseCheck.user_id}') "); String sqlCommand = sb.ToString(); manager.Read(sqlCommand); manager.Close(); }
/// <summary> /// This method gets called when the Server detects a new Answer to an Open Question. Add this answer to the open questions and /// close it. /// </summary> /// <param name="newAnswerNonsenseCheck">The model containing the answer to add, the user who wrote it, and the question_id to refer to.</param> public static int SaveAnswerToOpenQuestion(NewAnswerOffenseCheck newAnswerNonsenseCheck) { // Store the answer int ansId = assignAnswerIdToNewAnswer(newAnswerNonsenseCheck.answer, newAnswerNonsenseCheck.user_id); // Add a reference to the answer to the question DBManager manager = new DBManager(true); // Reference the new answer from the questions table StringBuilder sb = new StringBuilder(); sb.Append("UPDATE dbo.Questions "); sb.Append($"SET answer_id = {ansId} "); sb.Append($"WHERE question_id = {newAnswerNonsenseCheck.question_id}; "); String sqlCommand = sb.ToString(); manager.Read(sqlCommand); manager.Close(); return(ansId); }