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; }
public void AddQuestionToTest(int questionId, int testId, DbContext dbCtx) { QuestionService qservice= new QuestionService(dbCtx); TestService tservice = new TestService(dbCtx); Question q = qservice.Find(questionId); Test t = tservice.Find(testId); t.Questions.Add(q); q.TestsList.Add(t); qservice.QuestionManager.Update(q); tservice.TestManager.Update(t); }
// This is the Insert method to insert the entered TestSetup item // USAGE: <asp:FormView InsertMethod="InsertItem"> public void InsertItem() { using (_db) { var testDropdown = formviewID.FindControl("testDrpdwn") as DropDownList; var item = new Authorization_App.Model.TestSetup(); if (ViewState["expDate"]!=null) { item.ExpiresAt = (DateTime)ViewState["expDate"]; } //We use System.Guid to generate a random string. The parameter "N" is used to set the format. //It means 32 digits without hyphens and braces. string rand32digString = System.Guid.NewGuid().ToString("N"); //We will need only the first 8 digits of this string. item.Code = rand32digString.Substring(0,8); string userId = HttpContext.Current.User.Identity.GetUserId(); item.AuthorId = userId; var selectedTest = testDropdown.SelectedItem; TestService testService = new TestService(_db); Model.Test t =testService.Find(selectedTest.Text); if(t!=null) { item.TestId = t.Id; } TryUpdateModel(item); if (ModelState.IsValid) { // Save changes _db.TestSetup.Add(item); _db.SaveChanges(); Response.Redirect("Default"); } } }
protected void SubmitBtn_Click(object sender, EventArgs e) { // Click the button --> search for TestSetup with the same code as the code in the TextField --> if yes // open the test with the same ID as the TestId field of TestSetup. If no, redirect to error page. string code = CodeTextBox.Text; TestService testService = new TestService(_db); Test ts = testService.FindTestByCode(code); if (ts!= null) { Session["Test"] = ts; Response.Redirect("Interview"); } else { wrongCodeLabel.Visible = true; } }
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)}); } } }
private void DisplayTextOption() { int crrQuestionNum = (int) ViewState["CurrentQuestionNumber"]; TestService testService = new TestService(_db); QuestionService questionService = new QuestionService(_db); Test ts = Session["Test"] as Test; Question q = testService.FindQuestionInTestByIndex(ts.Id, crrQuestionNum); TextBoxAnswer.Visible = true; }
private void DisplayRadioBoxOptions() { int crrQuestionNum = (int) ViewState["CurrentQuestionNumber"]; TestService testService = new TestService(_db); QuestionService questionService = new QuestionService(_db); Test ts = Session["Test"] as Test; Question q = testService.FindQuestionInTestByIndex(ts.Id, crrQuestionNum); RadioButtonListAnswer.Visible = true; List<string> optionsContent = new List<string>(); foreach(QuestionOption qo in q.QuestionOption) { optionsContent.Add(qo.Content); } RadioButtonListAnswer.DataSource = optionsContent; RadioButtonListAnswer.DataBind(); }
protected void QuestionCheckbox_CheckedChanged(object sender, EventArgs e) { CheckBox cb = sender as CheckBox; HiddenField hf = null; foreach (Control c in cb.Parent.Controls) { if (c is HiddenField) { hf = c as HiddenField; } } int id; List<int> checkBoxIds = new List<int>(); if (!Int32.TryParse(hf.Value, out id)) { throw new InvalidCastException(); } TestService testService = new TestService(_db); foreach (string key in ViewState.Keys) { if (key == "checkBoxIds") { checkBoxIds = ViewState["checkBoxIds"] as List<int>; testService.manageList(checkBoxIds, cb.Checked, id); ViewState["checkBoxIds"] = checkBoxIds; } } testService.manageList(checkBoxIds, cb.Checked, id); ViewState["checkBoxIds"] = checkBoxIds; }
protected void AddButton_Click(object sender, EventArgs e) { IList<string> segments = null; int itemId=0; if (Request != null) { segments = Request.GetFriendlyUrlSegments(); Int32.TryParse(segments[0], out itemId); } TestService testService = new TestService(_db); List<int> checkBoxIds = ViewState["checkBoxIds"] as List<int>; if (checkBoxIds != null) { foreach (int questionId in checkBoxIds) { testService.AddQuestionToTest(questionId, itemId, _db); } StatusLabel.Text = "Questions successfuly added!"; } else { StatusLabel.Text= "You did not make any changes to the questions."; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewState["expDate"] = DateTime.Now.AddDays(1); var ExpiresAtClndr = formviewID.FindControl("ExpiresAtClndr") as Calendar; ExpiresAtClndr.SelectionChanged += new EventHandler(this.ExpiresAtClndr_SelectionChanged); var testDropdown = formviewID.FindControl("testDrpdwn") as DropDownList; //populate dropdown list here TestService testService = new TestService(_db); var testQuery = testService.GetAll(); List<string> testList = new List<string>(); foreach (Model.Test t in testQuery) { testList.Add(t.Name); } testDropdown.DataSource = testList; testDropdown.DataBind(); } }