/// <summary> /// This method temporarily saves the given answer to the question of the quiz. /// It does not save the given answer in the database until "Submit()" is called. /// </summary> /// <param name="question">question to answer</param> /// <param name="optionString">option string of the question to answer, or null to clear already the given answer of the question</param> /// <returns>true if success, otherwise false</returns> public bool GiveAnswer(Question.Question question, string optionString) { if (!IsAnswerSheetEditableForLoggedInUser()) { return(false); } if ((object)question == null) { return(false); } if (_quizQuestionList.IndexOf(question) == -1) { return(false); } if (string.IsNullOrWhiteSpace(optionString)) { RemoveFromPendingSubmissionList(question.QuestionID); return(true); } int optionID = question.GetOptionID(optionString); if (optionID == -1) { return(false); } AddOrReplaceToPendingSubmissionList(question.QuestionID, optionID); return(true); }
/// <summary> /// Shows given answer of submitted answer sheet /// </summary> /// <param name="question"></param> /// <returns>given answer if success, otherwise null</returns> public string ShowGivenAnswer(Question.Question question) { if (!IsSubmitted) { return(null); } if ((object)question == null) { return(null); } if (_quizQuestionList.IndexOf(question) == -1) { return(null); } DataTable dataTable = DataAccessLayer.SelectCommand(DataAccessLayer.SelectCommandString( "Option_ID", AnswerSheetTable, "Result_ID = :resultID AND Question_ID = :questionID"), new CommandParameter(":resultID", _resultID), new CommandParameter(":questionID", question.QuestionID)); if (dataTable.Rows.Count != 1) { return(null); } int optionID = (int)(decimal)(dataTable.Rows[0][0]); return(question.GetAnswerOptionByOptionID(optionID)); }
private bool AddQuestionCore(Question.Question question) { if (this.Topic != question.Topic) { return(false); } if (_questionList.IndexOf(question) != -1) { return(false); } int quizQuestionID; int returnValue = DataAccessLayer.InsertCommand_AllColumnAutoID(out quizQuestionID, QuizQuestionTable, ":quizID, :questionID, :questionOrder", QuizQuestionTableID, new CommandParameter(":quizID", QuizID), new CommandParameter("quiestionID", question.QuestionID), new CommandParameter(":questionOrder", _quizQuestionIDList.Count)); if (returnValue != 0) { return(false); } _quizQuestionIDList.Add(quizQuestionID); _questionList.Add(question); return(true); }
/// <summary> /// Deletes the given question to the quiz /// </summary> /// <param name="question">question to delete</param> /// <returns>true if success, otherwise false</returns> public bool DeleteQuestion(Question.Question question) { if (!IsQuizEditableForLoggedInUser()) { return(false); } if ((object)question == null) { return(false); } return(DeleteQuestionCore(question)); }
/// <summary> /// Reorders questions by moving the question from the current order to the new order /// </summary> /// <param name="currentOrder">zero-based current order from which the question will be moved</param> /// <param name="newOrder">zero-based new order to which the question will be moved</param> /// <returns>true if success, otherwise false</returns> public bool ReorderQuestion(int currentOrder, int newOrder) { if (!IsQuizEditableForLoggedInUser()) { return(false); } if (currentOrder < 0 || currentOrder >= _quizQuestionIDList.Count) { return(false); } if (newOrder < 0 || newOrder >= _quizQuestionIDList.Count) { return(false); } if (currentOrder == newOrder) { return(true); } bool isSuccessful; if (currentOrder < newOrder) { isSuccessful = ChangeQuestionOrders(currentOrder + 1, newOrder - currentOrder, currentOrder); } else { isSuccessful = ChangeQuestionOrders(newOrder, currentOrder - newOrder, newOrder + 1); } if (!isSuccessful) { return(false); } int quizQuestionID = _quizQuestionIDList[currentOrder]; Question.Question question = _questionList[currentOrder]; _quizQuestionIDList.RemoveAt(currentOrder); _questionList.RemoveAt(currentOrder); _quizQuestionIDList.Insert(newOrder, quizQuestionID); _questionList.Insert(newOrder, question); return(true); }
private bool DeleteQuestionCore(Question.Question question) { int findIndex = _questionList.IndexOf(question); if (findIndex == -1) { return(false); } int returnValue = DataAccessLayer.DeleteCommand(DataAccessLayer.DeleteCommandString(QuizQuestionTable, QuizQuestionTableID + " = :quizQuestionID"), new CommandParameter(":quizQuestionID", _quizQuestionIDList[findIndex])); if (returnValue != 0) { return(false); } _quizQuestionIDList.RemoveAt(findIndex); _questionList.RemoveAt(findIndex); return(true); }