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;
        }
예제 #2
0
        // Model binding method to get List of QuestionOption entries
        // USAGE: <asp:ListView SelectMethod="GetData">
        public IQueryable<Authorization_App.Model.QuestionOption> GetData()
        {
            int questionId = (int) Session["questionId"];
            QuestionService questionService = new QuestionService(_db);
            return questionService.GetOptionsForQuestion(questionId);

            //return _db.QuestionOption.Include(m => m.Question);
        }
예제 #3
0
        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);
        }
예제 #4
0
        // This is the Delete methd to delete the selected Question item
        // USAGE: <asp:FormView DeleteMethod="DeleteItem">
        public void DeleteItem(int Id)
        {
            //using (_db)
            //{
            //    var item = _db.Question.Find(Id);

            //    if (item != null)
            //    {
            //        _db.Question.Remove(item);
            //        _db.SaveChanges();
            //    }
            //}
            QuestionService questionService = new QuestionService(_db);
            questionService.Delete(Id);

            Response.Redirect("../Default");
        }
예제 #5
0
        public bool isAdded(string questionId)
        {
            Authorization_App.DataAccess.ApplicationDbContext _dbCtx = new Authorization_App.DataAccess.ApplicationDbContext();
            using (_dbCtx)
            {
                int qId = 0;
                Int32.TryParse(questionId, out qId);
                IList<string> segments = null;
                int testId = 0;

                if (Request != null)
                {
                    segments = Request.GetFriendlyUrlSegments();
                    Int32.TryParse(segments[0], out testId);
                }
                QuestionService questionService = new QuestionService(_dbCtx);
                bool res = questionService.isAdded(qId, testId);
                _dbCtx.Dispose();
                return res;
            }
        }
예제 #6
0
        // This is the Insert method to insert the entered QuestionOption item
        // USAGE: <asp:FormView InsertMethod="InsertItem">
        public void InsertItem()
        {
            using (_db)
            {
                var item = new Authorization_App.Model.QuestionOption();
                int questionId = (int) Session["questionId"];

                QuestionService questionService = new QuestionService(_db);
                questionService.AddOptionToQuestion(questionId, item);

                TryUpdateModel(item);

                if (ModelState.IsValid)
                {
                    // Save changes
                    _db.QuestionOption.Add(item);
                    _db.SaveChanges();

                    Response.Redirect("Default");
                }
            }
        }
 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();
 }