public ActionResult DeleteQuestion(long id, FormCollection collection) { try { QuestionFactory DeleteQuestion = new QuestionFactory(); QuestionEntity Question = new QuestionEntity(); Question = DeleteQuestion.GetQuestionById(id); DataLayer.tblQuestion NewQuestion = new DataLayer.tblQuestion(); NewQuestion.QuestionId = id; NewQuestion.QuizId = Question.QuizId; NewQuestion.Question = Question.Question; NewQuestion.CreatedDate = Question.CreatedDate; NewQuestion.CreatedBy = Question.CreatedBy; NewQuestion.UpdatedDate = DateTime.Now; NewQuestion.UpdatedBy = null; NewQuestion.IsActive = false; // IsActive will be false in delete record DeleteQuestion.SaveQuestion(NewQuestion); return(RedirectToAction("Question")); } catch { return(View()); } }
public ActionResult AddQuestion(QuestionEntity questionEntity) { try { if (ModelState.IsValid) { ValidationFactory VF = new ValidationFactory(); QuestionFactory AddQuestion = new QuestionFactory(); DataLayer.tblQuestion NewQuestion = new DataLayer.tblQuestion(); DataLayer.tblQuiz NewQuiz = new DataLayer.tblQuiz(); string Message = VF.QuestionValidity(questionEntity.Question, null); if (Message != "Success") { ModelState.AddModelError("Question", Message); GetQuiz(); return(View(questionEntity)); } else { NewQuestion.Question = questionEntity.Question; NewQuestion.QuizId = questionEntity.QuizId; NewQuestion.IsMultiple = questionEntity.IsMultiple; NewQuestion.CreatedDate = DateTime.Now; NewQuestion.CreatedBy = null; NewQuestion.UpdatedDate = null; NewQuestion.UpdatedBy = null; NewQuestion.IsActive = true; AddQuestion.SaveQuestion(NewQuestion); return(RedirectToAction("Question")); } } else { GetQuiz(); return(View(questionEntity)); } } catch (Exception Ex) { return(View()); } finally { GetQuiz(); } }
public ActionResult EditQuestion(long id, QuestionEntity questionEntity) { try { if (ModelState.IsValid) { QuestionFactory EditQuestion = new QuestionFactory(); DataLayer.tblQuestion NewQuestion = new DataLayer.tblQuestion(); ValidationFactory VF = new ValidationFactory(); string Message = VF.QuestionValidity(questionEntity.Question, id); if (Message != "Success") { ModelState.AddModelError("QuestionName", Message); GetQuiz(); return(View(questionEntity)); } else { NewQuestion.QuestionId = id; NewQuestion.Question = questionEntity.Question; NewQuestion.CreatedDate = questionEntity.CreatedDate; NewQuestion.CreatedBy = null; NewQuestion.QuizId = questionEntity.QuizId; NewQuestion.UpdatedDate = DateTime.Now; NewQuestion.UpdatedBy = null; NewQuestion.IsActive = questionEntity.IsActive; EditQuestion.SaveQuestion(NewQuestion); return(RedirectToAction("Question")); } } else { return(View(questionEntity)); } } catch { return(View()); } finally { GetQuiz(); } }