protected void NextQuestionBtn_Click(object sender, EventArgs e) { int crrQuestionNum = (int) ViewState["CurrentQuestionNumber"]; TestService testService = new TestService(_db); QuestionService questionService = new QuestionService(_db); TestReportService testReportService = new TestReportService(); Test ts = Session["Test"] as Test; Question q = null; if (ts!= null) { ClearAllOptions(); q = testService.FindQuestionInTestByIndex(ts.Id, crrQuestionNum); if (q != null) { QuestionText.Text = q.Description; NextQuestionBtn.Text = testService.IsLastQuestionInTest(q, ts) ? "Finish Test" : "Next"; string type = questionService.GetQuestionType(q); IRuleAction rule = ruleActions.FirstOrDefault(r => r.IsValidated(type)); rule.Action.Invoke(); } else { QuestionText.Text = ""; NextQuestionBtn.Visible = false; SubmitTestBtn.Visible = true; } } crrQuestionNum++; ViewState["CurrentQuestionNumber"] = crrQuestionNum; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewState["CurrentQuestionNumber"] = 0; NextQuestionBtn.Text = "Start"; Test ts = Session["Test"] as Test; TestService testService = new TestService(_db); TestReportService testReportService = new TestReportService(); if (ts != null) { testReport = new TestReport(); testReport.AuthorId = ts.AuthorId; testReport.TestId = ts.Id; testReport.QuestionIds = testService.GetQuestionIds(ts); testReportService.Add(testReport); //testReportService.Add(new TestReport() { AuthorId = ts.AuthorId, TestId = ts.Id, QuestionIds = testService.GetQuestionIds(ts)}); } } }