public void AddQuestionFormView_InsertItem(Question question) { // checks if any option match the correct answer if (String.Compare(question.CorrectAnswer.ToUpper(), question.AnswerOption1.ToUpper()) == 0 || String.Compare(question.CorrectAnswer.ToUpper(), question.AnswerOption2.ToUpper()) == 0 || String.Compare(question.CorrectAnswer.ToUpper(), question.AnswerOption3.ToUpper()) == 0 || String.Compare(question.CorrectAnswer.ToUpper(), question.AnswerOption4.ToUpper()) == 0) { if (ModelState.IsValid) { try { Service.SaveQuestion(question); Page.SetTempData("SuccessMessage", "The question has been added"); Response.RedirectToRoute("Questions"); Context.ApplicationInstance.CompleteRequest(); } catch { ModelState.AddModelError(String.Empty, "An error occured when the question was to be saved."); } } } else { ModelState.AddModelError(String.Empty, "None of the entered answer options match the correct answer!."); } }
public void SaveQuestion(Question question) { // Validering ICollection<ValidationResult> validationResults; if (!question.Validate(out validationResults)) { var ex = new ValidationException("Objektet klarade inte valideringen."); ex.Data.Add("ValidationResults", validationResults); throw ex; } if (question.QuestionID == 0) { QuestionDAL.AddQuestion(question); } else { QuestionDAL.EditQuestion(question); } }
public void DeleteQuestion(Question question) { DeleteQuestion(question.QuestionID); }