public ActionResult DeleteQuiz(long id) { try { QuizFactory DeleteQuiz = new QuizFactory(); QuizEntity Quiz = new QuizEntity(); Quiz = DeleteQuiz.GetQuizById(id); DataLayer.tblQuiz NewQuiz = new DataLayer.tblQuiz(); NewQuiz.QuizId = id; NewQuiz.QuizName = Quiz.QuizName; NewQuiz.CreatedDate = Quiz.CreatedDate; NewQuiz.CreatedBy = Quiz.CreatedBy; NewQuiz.UpdatedDate = DateTime.Now; NewQuiz.UpdatedBy = null; NewQuiz.IsActive = false; // IsActive will be false in delete record DeleteQuiz.SaveQuiz(NewQuiz); return(RedirectToAction("Quiz")); } 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(); } }
//POST: Save Option public JsonResult AddOption(QuestionOptionMappingEntity queOp) { try { if (ModelState.IsValid) { ValidationFactory VF = new ValidationFactory(); QuestionOptionMappingFactory AddOption = new QuestionOptionMappingFactory(); DataLayer.tblQuestionOptionMapping NewQO = new DataLayer.tblQuestionOptionMapping(); DataLayer.tblQuiz NewQuiz = new DataLayer.tblQuiz(); string Message = VF.OptionValidity(queOp.QuestionOptionText, null, queOp.QuestionId); if (Message != "Success") { ModelState.AddModelError("Question", Message); GetQuiz(); return(Json("Option Already Exist.", JsonRequestBehavior.AllowGet)); } else { NewQO.QuestionId = queOp.QuestionId; NewQO.QuestionOptionText = queOp.QuestionOptionText; NewQO.IsTrue = queOp.IsTrue; NewQO.CreatedDate = DateTime.Now; NewQO.CreatedBy = null; NewQO.UpdatedDate = null; NewQO.UpdatedBy = null; NewQO.IsActive = true; AddOption.SaveOption(NewQO); return(Json("Record added sucessfully", JsonRequestBehavior.AllowGet)); } } else { GetQuiz(); return(Json("", JsonRequestBehavior.AllowGet)); } } catch (Exception Ex) { return(Json("Something went wrong.", JsonRequestBehavior.AllowGet)); } finally { GetQuiz(); } }
public ActionResult EditQuiz(int id, QuizEntity Quiz) { try { if (ModelState.IsValid) { QuizFactory EditQuiz = new QuizFactory(); DataLayer.tblQuiz NewQuiz = new DataLayer.tblQuiz(); ValidationFactory VF = new ValidationFactory(); string Message = VF.QuizValidity(Quiz.QuizName, id); if (Message != "Success") { ModelState.AddModelError("QuizName", Message); return(View(Quiz)); } else { NewQuiz.QuizId = id; NewQuiz.QuizName = Quiz.QuizName; NewQuiz.CreatedDate = Quiz.CreatedDate; NewQuiz.CreatedBy = null; NewQuiz.UpdatedDate = DateTime.Now; NewQuiz.UpdatedBy = null; NewQuiz.IsActive = Quiz.IsActive; EditQuiz.SaveQuiz(NewQuiz); return(RedirectToAction("Quiz")); } } else { return(View(Quiz)); } } catch { return(View()); } }