/// <summary>
        /// 添加试题
        /// </summary>
        /// <param name="id">试题id</param>
        /// <param name="testpaperid">试卷id</param>
        /// <param name="testType">跳转前的试卷类型</param>
        /// <param name="subject">跳转前的试题科目</param>
        /// <param name="section">跳转前的试题章节</param>
        /// <param name="diffcult">跳转前的试题难易程度</param>
        /// <returns></returns>
        public ActionResult Add(Guid?id, int?testpaperid, string type, string subject, string section, string diffcult)
        {
            TestPaperInfo testPaperInfo = db.TestPaperInfoes.Find(testpaperid);

            switch (type)
            {
            case "选择题":
                ChoiceQuestion choicequestion = db.ChoiceQuestions.Find(id);
                testPaperInfo.ChoiceQuestions.Add(choicequestion);
                break;

            case "填空题":
                FillQuestion fillquestion = db.FillQuestions.Find(id);
                testPaperInfo.FillQuestions.Add(fillquestion);
                break;

            case "判断题":
                CheckQuestion checkquestion = db.CheckQuestions.Find(id);
                testPaperInfo.CheckQuestions.Add(checkquestion);
                break;

            case "计算题":
                CalculateQuestion calculatate = db.CalculateQuestion.Find(id);
                testPaperInfo.CalculateQuestions.Add(calculatate);
                break;
            }
            db.SaveChanges();//保存数据
            //返回到添加试题页面
            return(RedirectToAction("AddQuestions", new { id = testpaperid, testType = type, subject = subject, section = section, diffcult = diffcult }));
        }
Ejemplo n.º 2
0
        public static bool AddChoiceQuestion(Question question, ChoiceQuestion detail)
        {
            context.Questions.Add(question);

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(false);
            }

            detail.qid = question.qid;
            context.ChoiceQuestions.Add(detail);

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public Question Convert(QuestionResource questionResource)
        {
            var existingQuestion = CreatedQuestions.Where(obj => obj.Id == questionResource.Id).FirstOrDefault();

            if (existingQuestion != null)
            {
                if (existingQuestion is ChoiceQuestion)
                {
                    Assign(existingQuestion as ChoiceQuestion, questionResource);
                }
                else if (existingQuestion is TextQuestion)
                {
                    Assign(existingQuestion as TextQuestion, questionResource);
                }
                return(existingQuestion);
            }
            else
            {
                if (questionResource.DefaultChoice == null)
                {
                    var newChoiceQuestion = new ChoiceQuestion();
                    CreatedQuestions.Add(newChoiceQuestion);
                    Assign(newChoiceQuestion, questionResource);
                    return(newChoiceQuestion);
                }
                else
                {
                    var newTextQuestion = new TextQuestion();
                    CreatedQuestions.Add(newTextQuestion);
                    Assign(newTextQuestion, questionResource);
                    return(newTextQuestion);
                }
            }
        }
Ejemplo n.º 4
0
        public ChoiceQuestionViewModel(AppShell appShell, ChoiceQuestion choiceQuestion)
        {
            this.Question   = choiceQuestion.QuestionText;
            this.BaseObject = choiceQuestion;
            this.Title      = "Otázka " + NumberOfQuestion;
            NumberOfQuestion++;
            this.AppShell        = appShell;
            this.ConfirmQuestion = new Command(OnAnswerConfirmed);

            Choices = new ObservableCollection <ChoiceForChoiceQuestionViewModel>();

            foreach (ChoiceForChoiceQuestion choice in choiceQuestion.Choices)
            {
                var newChoice = new ChoiceForChoiceQuestionViewModel(this, choice);
                Choices.Add(newChoice);
            }

            FlyOutItem = new FlyoutItem()
            {
                Title = this.Title,
                Icon  = "icon_question.png",
            };

            TextQuestionPage = new ChoiceQuestionPage(this)
            {
                Title = this.Title
            };

            ShellContent = new ShellContent {
                Content = TextQuestionPage
            };

            FlyOutItem.Items.Add(ShellContent);
        }
Ejemplo n.º 5
0
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, QuestionDTO questionDTO)
        {
            try
            {
                ValidateQuestionCreate(questionDTO);
                if (ModelState.IsValid)
                {
                    ChoiceQuestion choiceQuestion = new ChoiceQuestion
                    {
                        Id             = 0,
                        AspNetUsersId  = User.Identity.GetUserId(),
                        OneChoice      = true, //for some reason; disabling the OneChoice prompt in RAZOR turns this to false.. This is a hack
                        UsedInGame     = false,
                        ACLId          = 1,
                        QuestionTypeId = questionDTO.QuestionTypeId,
                        Name           = questionDTO.Name,
                        Text           = questionDTO.Text,
                        Tags           = questionDTO.Tags
                    };

                    db.Question.Add(choiceQuestion);
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);
                    questionDTO.Id = choiceQuestion.Id; //pass back the new Id to the client
                }

                return(Json(new[] { questionDTO }.ToDataSourceResult(request, ModelState)));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR);
                return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
            }
        }//public JsonResult Create([DataSourceRequest] DataSourceRequest request, QuestionDTO questionDTO)
        internal static Product House()
        {
            Product p = Product.CreateDraft(
                "HSI",
                "Happy House",
                "/static/house.jpg",
                "House insurance",
                5);

            p.AddCover("C1", "Fire", "", false, 200000);
            p.AddCover("C2", "Flood", "", false, 100000);
            p.AddCover("C3", "Theft", "", false, 50000);
            p.AddCover("C4", "Assistance", "", true, null);

            p.AddQuestions(new List <Question> {
                new ChoiceQuestion("TYP", 1, "Apartment / House", new List <Choice> {
                    new Choice("APT", "Apartment"),
                    new Choice("HOUSE", "House")
                }),
                new NumericQuestion("AREA", 2, "Area"),
                new NumericQuestion("NUM_OF_CLAIM", 3, "Number of claims in last 5 years"),
                new ChoiceQuestion("FLOOD", 4, "Located in flood risk area", ChoiceQuestion.YesNoChoice())
            });
            p.Activate();
            return(p);
        }
        internal static Product Farm()
        {
            Product p = Product.CreateDraft(
                "FAI",
                "Happy farm",
                "/static/farm.jpg",
                "Farm insurance",
                1);

            p.AddCover("C1", "Crops", "", false, 200000);
            p.AddCover("C2", "Flood", "", false, 100000);
            p.AddCover("C3", "Fire", "", false, 50000);
            p.AddCover("C4", "Equipment", "", true, 300000);

            p.AddQuestions(new List <Question> {
                new ChoiceQuestion("TYP", 1, "Cultivation type", new List <Choice> {
                    new Choice("ZB", "Crop"),
                    new Choice("KW", "Vegetable")
                }),
                new NumericQuestion("AREA", 2, "Area"),
                new NumericQuestion("NUM_OF_CLAIM", 3, "Number of claims in last 5 years"),
                new ChoiceQuestion("FLOOD", 4, "Located in flood risk area", ChoiceQuestion.YesNoChoice())
            });
            p.Activate();
            return(p);
        }
Ejemplo n.º 8
0
        public void Create_Always_WillSetTheListOfPossibleAnswers()
        {
            var singleChoiceQuestionFactory = new SingleChoiceQuestionFactory();

            ChoiceQuestion choiceQuestion = singleChoiceQuestionFactory.Create("SC Sex 2 Female Male");

            Assert.AreEqual(2, choiceQuestion.Items.Count);
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            ChoiceQuestion choiceQuestion = db.ChoiceQuestions.Find(id);

            db.ChoiceQuestions.Remove(choiceQuestion);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public void Create_Always_WillCreateASingleChoiceQuestion()
        {
            var singleChoiceQuestionFactory = new SingleChoiceQuestionFactory();

            ChoiceQuestion choiceQuestion = singleChoiceQuestionFactory.Create("SC Sex 2 Female Male");

            Assert.IsInstanceOf(typeof(SingleChoiceQuestion), choiceQuestion);
        }
        public void Create_WhenMC_WillCreateAMultipleChoiceQuestion()
        {
            var singleChoiceQuestionFactory = new MultipleChoiceQuestionFactory();

            ChoiceQuestion choiceQuestion = singleChoiceQuestionFactory.Create("MC Optiuni 3 op1 op2 op3");

            Assert.AreEqual(3, choiceQuestion.Items.Count);
        }
        public void Create_Always_WillCreateAmultipleChoiceQuestion()
        {
            var multipleChoiceQuestionFactory = new MultipleChoiceQuestionFactory();

            ChoiceQuestion choiceQuestion = multipleChoiceQuestionFactory.Create("MC Optiuni 3 op1 op2 op3");

            Assert.IsInstanceOf(typeof(MultipleChoiceQuestion), choiceQuestion);
        }
Ejemplo n.º 13
0
        }//CloneQuestions

        /*
         * Will delete the question and all artifacts associated with that question. question/choicequestion,
         * choice records.
         */
        public static void DeleteQuestion(Controller controller, ProbeDataContext db, long questionId)
        {
            ChoiceQuestion cq = db.ChoiceQuestion.Find(questionId);

            db.Choice.RemoveRange(cq.Choices);

            db.ChoiceQuestion.Remove(cq);
            db.SaveChanges(controller.Request != null ? controller.Request.LogonUserIdentity.Name : null);
        }//DeleteQuestion
Ejemplo n.º 14
0
        public void Create_Always_WillSetQuestionName()
        {
            var singleChoiceQuestionFactory = new SingleChoiceQuestionFactory();

            ChoiceQuestion choiceQuestion = singleChoiceQuestionFactory.CreateChoiceQuestion("SC Sex 2 Female Male");

            Assert.IsInstanceOf(typeof(SingleChoiceQuestion), choiceQuestion);
            Assert.AreEqual("Sex", choiceQuestion.Name);
        }
 public ActionResult Edit([Bind(Include = "Id,Title,Options,Answer,Score,Subject,Section,Difficulty")] ChoiceQuestion choiceQuestion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(choiceQuestion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(choiceQuestion));
 }
Ejemplo n.º 16
0
        // GET: Choices
        public ActionResult Index(long questionid)
        {
            ChoiceQuestion question = db.ChoiceQuestion.Find(questionid);

            ViewBag.QuestionId   = questionid;
            ViewBag.QuestionName = question.Name;
            ViewBag.QuestionText = question.Text;

            return(View());
        }
        public ActionResult Create([Bind(Include = "Id,Title,Options,Answer,Score,Subject,Section,Difficulty")] ChoiceQuestion choiceQuestion)
        {
            if (ModelState.IsValid)
            {
                choiceQuestion.Id = Guid.NewGuid();
                db.ChoiceQuestions.Add(choiceQuestion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(choiceQuestion));
        }
Ejemplo n.º 18
0
        public ChoiceQuestionService(AppShell appShell, ChoiceQuestion textQuestion, MapService mapService)
        {
            Model = textQuestion;

            Model.Service = this;

            MapService = mapService;

            ViewModel = new ChoiceQuestionViewModel(appShell, textQuestion);

            ViewModel.ConfirmedQuestionEvent += OnConfirm;
        }
Ejemplo n.º 19
0
 internal void PickValues(ChoiceQuestion choiceQuestion)
 {
     _choiceQuestion          = choiceQuestion;
     textBoxQuestionText.Text = _choiceQuestion.QuestionText;
     textBoxName.Text         = _choiceQuestion.Name;
     if (_choiceQuestion.EnumList != null)
     {
         if (_choiceQuestion.Configuration.EnumerationLists.Contains(_choiceQuestion.EnumList))
         {
             comboBoxAnswerList.SelectedItem = _choiceQuestion.EnumList;
         }
     }
 }
        // GET: ChoiceQuestions/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChoiceQuestion choiceQuestion = db.ChoiceQuestions.Find(id);

            if (choiceQuestion == null)
            {
                return(HttpNotFound());
            }
            return(View(choiceQuestion));
        }
Ejemplo n.º 21
0
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, GameQuestionDTO gameQuestionDTO)
        {
            try
            {
                //check to ensure the user owns the resources she is trying to access. if not; we get out of here.
                //Somebody is trying to do bad stuff.
                if (!ProbeValidate.IsGameForLoggedInUser((long)gameQuestionDTO.GameId))
                {
                    ModelState.AddModelError("", "The attempt to add a game question was not successful");
                    return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
                }
                if (!ProbeValidate.IsQuestionForLoggedInUser((long)gameQuestionDTO.QuestionId))
                {
                    ModelState.AddModelError("", "The attempt to add a game question was not successful");
                    return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
                }

                //transform DTO to business object (GameQuestion)
                GameQuestion gameQuestion = new GameQuestion
                {
                    Id         = 0,
                    GameId     = gameQuestionDTO.GameId,
                    QuestionId = gameQuestionDTO.QuestionId,
                    OrderNbr   = gameQuestionDTO.OrderNbr,
                    Weight     = gameQuestionDTO.Weight
                };

                //We need to clone the question and set the UsedInGame field to true. The cloned questions
                //is what will be associated with the game
                ChoiceQuestion clonedQuestion = ProbeQuestion.CloneQuestion(this, ref db, true, gameQuestion.QuestionId);
                gameQuestion.Question = clonedQuestion; //we do a switch to the cloned question


                db.GameQuestion.Add(gameQuestion);
                db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);
                gameQuestionDTO.Id = gameQuestion.Id; //pass back the new Id to the client

                return(Json(new[] { gameQuestionDTO }.ToDataSourceResult(request, ModelState)));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR);
                return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
            }
        }
Ejemplo n.º 22
0
        /*
         * Will clone the question and all artifacts associated with that question. question/choicequestion,
         * choice records. Returns the cloned question (that hasn't been saved in database yet). Calling function needs
         * to call db.SaveChanges
         */
        public static ChoiceQuestion CloneQuestion(Controller controller, ref ProbeDataContext db, bool forQuestionInUse, long sourceQuestionId)
        {
            //clone question
            ChoiceQuestion cqSource = db.ChoiceQuestion.Find(sourceQuestionId);

            string newName = cqSource.Name;

            if (!forQuestionInUse)
            {
                newName = GetClonedQuestionName(cqSource.Name);
            }

            ChoiceQuestion cqNew = new ChoiceQuestion
            {
                AspNetUsersId  = cqSource.AspNetUsersId,
                QuestionTypeId = cqSource.QuestionTypeId,
                Name           = newName,
                Text           = cqSource.Text,
                Tags           = cqSource.Tags,
                OneChoice      = cqSource.OneChoice,
                ACLId          = cqSource.ACLId,
                UsedInGame     = forQuestionInUse,
            };


            db.Question.Add(cqNew);

            ChoiceQuestion cqOrg = db.ChoiceQuestion.Find(sourceQuestionId);

            //clone choices
            foreach (Choice c in cqOrg.Choices)
            {
                Choice newC = new Choice
                {
                    ChoiceQuestion = cqNew,
                    Name           = c.Name,
                    Text           = c.Text,
                    OrderNbr       = c.OrderNbr,
                    Correct        = c.Correct
                };

                db.Choice.Add(newC);
            }

            return(cqNew);
        }//CloneQuestions
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            List <IQuestion> questions = new List <IQuestion>();

            Question first = new Question();

            first.difficulty = 3;
            first.setText("Who was the inventor of Java?");
            first.setAnswer("James Gosling");
            questions.Add(first);

            ChoiceQuestion second = new ChoiceQuestion();

            second.difficulty = 1;
            second.setText("In which country was the inventor of Java born?");
            second.addChoice("Australia", false);
            second.addChoice("Canada", true);
            second.addChoice("Denmark", false);
            second.addChoice("United States", false);
            questions.Add(second);

            //Voorbeeld vragen voor het nachecken van de opdracht
            Question a = new Question();

            a.difficulty = 1;
            a.setText("a?");
            a.setAnswer("a");
            questions.Add(a);

            Question b = new Question();

            b.difficulty = 2;
            b.setText("b");
            b.setAnswer("b");
            questions.Add(b);

            Question c = new Question();

            c.difficulty = 3;
            c.setText("c");
            c.setAnswer("c");
            questions.Add(c);

            keuzeMenu(questions);
        }
Ejemplo n.º 24
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, QuestionDTO questionDTO)
        {
            try
            {
                //check to ensure the user owns the resources she is trying to access. if not; we get out of here.
                //Somebody is trying to do bad stuff.
                if (!ProbeValidate.IsQuestionForLoggedInUser((long)questionDTO.Id))
                {
                    ModelState.AddModelError("", "Question Update could not be accomplished");
                    return(Json(ModelState.ToDataSourceResult()));
                }

                ValidateQuestionEdit(questionDTO);
                if (ModelState.IsValid)
                {
                    ChoiceQuestion choiceQuestion = db.ChoiceQuestion.Find(questionDTO.Id);

                    //choiceQuestion.AspNetUsersId - THIS IS NOT CHANGING
                    choiceQuestion.QuestionTypeId = questionDTO.QuestionTypeId;
                    choiceQuestion.Name           = questionDTO.Name;
                    choiceQuestion.Text           = questionDTO.Text;
                    choiceQuestion.Tags           = questionDTO.Tags;
                    //choiceQuestion.OneChoice - THIS IS NOT CHANGING
                    //choiceQuestion.UsedInGame - THIS IS NOT CHANGING
                    //choiceQuestion.ACLId - THIS IS NOT CHANGING

                    db.Entry(choiceQuestion).State = EntityState.Modified;
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);
                }

                //return Json(ModelState.ToDataSourceResult());
                return(Json(new[] { questionDTO }.ToDataSourceResult(dsRequest, ModelState)));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR);
                return(Json(ModelState.ToDataSourceResult()));
            }
        }//public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, QuestionDTO questionDTO)
Ejemplo n.º 25
0
        }//public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, QuestionDTO questionDTO)

        // GET: ChoiceQuestions/Clone
        public JsonResult Clone(long id)
        {
            try
            {
                //limit the questions to only what the user possesses
                string loggedInUserId = (User.Identity.GetUserId() != null ? User.Identity.GetUserId() : "-1");

                ChoiceQuestion clonedQuestion = ProbeQuestion.CloneQuestion(this, ref db, false, id);
                db.Question.Add(clonedQuestion);
                db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);

                //The message that the calling RAZOR can use
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_QuestionCloneSuccessful,
                    MessageType = Helpers.Mics.MessageType.Informational,
                    Message     = @"The question <span style=""font-style:italic;font-weight:bold"">" +
                                  db.ChoiceQuestion.Find(id).Name + @"</span> has been cloned successfully to question <span style=""font-style:italic;font-weight:bold"">" +
                                  clonedQuestion.Name + @"</span>"
                };

                NotifyProbe.NotifyQuestionChanged(User.Identity.Name); //let all clients know where was a game change.

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                    MessageType = Helpers.Mics.MessageType.Error,
                    Message     = ProbeConstants.MSG_UnsuccessfulOperation_STR
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
        } //public JsonResult Clone(long id)
Ejemplo n.º 26
0
        public void LoadFromDatabase(LoggingManager log)
        {
            var qDataList = log.GetQuestionSetContent(Name);

            foreach (var questionData in qDataList)
            {
                Question q;
                switch ((Enums.Question)questionData.QuestionType)
                {
                case Enums.Question.Info:
                    q = new InfoScreen(questionData);
                    break;

                case Enums.Question.Text:
                    q = new TextQuestion(questionData);
                    break;

                case Enums.Question.Choice:
                    q = new ChoiceQuestion(questionData);
                    break;

                case Enums.Question.Scale:
                    q = new ScaleQuestion(questionData);
                    break;

                case Enums.Question.Ladder:
                    q = new LadderQuestion(questionData);
                    break;

                case Enums.Question.Stimuli:
                    q = new VisualStimuli(questionData);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                q.Jumps = log.GetJumps(questionData);
                Questions.Add(q);
            }
        }
Ejemplo n.º 27
0
        public static bool DeleteQuestion(Question question)
        {
            switch (question.type)
            {
            case (int)QuestionType.SINGLECHOICE:
            case (int)QuestionType.MULTICHOICE:
                ChoiceQuestion cdetail = GetChoiceQuestionByQid(question.qid);
                context.ChoiceQuestions.Remove(cdetail);
                break;

            case (int)QuestionType.FILLIN:
                FillQuestion fdetail = GetFillQuestionByQid(question.qid);
                context.FillQuestions.Remove(fdetail);
                break;

            case (int)QuestionType.DISCUSS:
                DiscussQuestion ddetail = GetDiscussQuestionByQid(question.qid);
                context.DiscussQuestions.Remove(ddetail);
                break;

            default:
                return(false);
            }

            context.Questions.Remove(question);

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 28
0
        void Assign(ChoiceQuestion choiceQuestion, QuestionResource questionResource)
        {
            choiceQuestion.Id = questionResource.Id;

            if (questionResource.QuestionText != null)
            {
                choiceQuestion.QuestionText = questionResource.QuestionText;
            }

            if ((questionResource.ChoicesThatOpensThis != null) && choiceQuestion.ChoicesThatOpensThis == null)
            {
                choiceQuestion.ChoicesThatOpensThis = new List <Choice>();

                foreach (ChoiceResource choiceResource in questionResource.ChoicesThatOpensThis)
                {
                    Choice newChoice = Convert(choiceResource);
                    choiceQuestion.ChoicesThatOpensThis.Add(newChoice);
                    if (newChoice.OpensQuestions == null)
                    {
                        newChoice.OpensQuestions = new List <Question>();
                    }
                    newChoice.OpensQuestions.Add(choiceQuestion);
                }
            }

            if ((questionResource.Choices != null) && choiceQuestion.Choices == null)
            {
                choiceQuestion.Choices = new List <ChoiceForChoiceQuestion>();

                foreach (ChoiceResource choiceResource in questionResource.Choices)
                {
                    ChoiceForChoiceQuestion newChoice = Convert(choiceResource) as ChoiceForChoiceQuestion;
                    choiceQuestion.Choices.Add(newChoice);
                    newChoice.Question = choiceQuestion;
                }
            }
        }
        private void OnQuestionTypeChange()
        {
            // Added to prevent a bug, the bind event sometimes will be called again and again
            if (Question.QuestionType == _lastQuestionType)
            {
                return;
            }

            if (_parameterSetState)
            {
                _parameterSetState = false;
                return;
            }

            Console.WriteLine("OnQuestionTypeChange");

            var questionText = Question.Question;
            var questionType = Question.QuestionType;

            if (questionType == "choice")
            {
                Question = new ChoiceQuestion();
                ((ChoiceQuestion)Question).Choices = new List <string>();
            }
            else if (questionType == "short_answer")
            {
                Question = new ShortAnswerQuestion();
            }

            Question.Question     = questionText;
            Question.QuestionType = questionType;
            _lastQuestionType     = questionType;

            QuestionUpdated.InvokeAsync(Question);
            StateHasChanged();
        }
Ejemplo n.º 30
0
 private void PopulateAnswers(ChoiceQuestion question, string answers)
 {
     foreach (var answer in answers.Split(','))
     {
         string cleanAnswer = answer.Trim();
         Choice choice = new Choice() { DisplayText = cleanAnswer, Value = cleanAnswer, Id = Guid.NewGuid() };
         question.AddChoice(choice);
     }
 }
Ejemplo n.º 31
0
 protected void Page_Init(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         init();
     }
     for (int i = 0; i < nrintrebari; i++)
     {
         if (questionlist[i].Type.Equals("Tip Grila"))
         {
             questions[i] = new ChoiceQuestion(chosenkeylist[i], questionlist[i], choices[i]);
         }
         else if (questionlist[i].Type.Equals("Standard"))
         {
             questions[i] = new InputQuestion(chosenkeylist[i], questionlist[i], false);
         }
         else if (questionlist[i].Type.Equals("Program"))
         {
             questions[i] = new InputQuestion(chosenkeylist[i], questionlist[i], true);
         }
         questions[i].display(tot);
     }
 }
Ejemplo n.º 32
0
        public async Task <ActionResult> Create(PaperViewModel paperInfo)
        {
            foreach (var item in paperInfo.SingleQuestions)
            {
                for (int i = 0; i < 4; i++)
                {
                    item.Options[i].OptionId = (OptionType)(i + 1);
                }
            }
            foreach (var item in paperInfo.MultipleQuestions)
            {
                for (int i = 0; i < item.Options.Count; i++)
                {
                    item.Options[i].OptionId = (OptionType)(i + 1);
                }
            }
            if (ModelState.IsValid)
            {
                var   teacher = GetCurrentUser() as Teacher;
                Paper paper   = new Paper();
                paper.Exam    = new Exam();
                paper.EditOn  = DateTime.Now;
                paper.Teacher = teacher;
                var trueOrFalseQuestionList = new List <TrueOrFalseQuestion>();
                foreach (TrueOrFalseQuestionViewModel questioninfo in paperInfo.TrueOrFalseQuestions)
                {
                    trueOrFalseQuestionList.Add(new TrueOrFalseQuestion
                    {
                        Type      = questioninfo.Type,
                        Content   = questioninfo.Content,
                        IsCorrect = questioninfo.IsCorrect,
                    });
                }
                ;
                var singleQuestionList = new List <ChoiceQuestion>();
                foreach (SingleQuestionViewModel questioninfo in paperInfo.SingleQuestions)
                {
                    ChoiceQuestion c = new ChoiceQuestion();
                    c.Type    = questioninfo.Type;
                    c.Content = questioninfo.Content;
                    for (int i = 0; i < 4; i++)
                    {
                        Option o = new Option
                        {
                            OptionProperty = questioninfo.Options[i].OptionProperty,
                            OptionId       = questioninfo.Options[i].OptionId
                        };
                        if ((i + 1) == questioninfo.CorrectAnswer)  //view中正确选项是从1开始的,和OptionId的枚举一致,所以这里要加一才能和正确选项相等。
                        {
                            o.IsCorrect = true;
                        }
                        c.Options.Add(o);
                    }
                    singleQuestionList.Add(c);
                }
                var multipleQuestionList = new List <ChoiceQuestion>();
                foreach (MultipleQuestionViewModel questioninfo in paperInfo.MultipleQuestions)
                {
                    ChoiceQuestion c = new ChoiceQuestion();
                    c.Type    = questioninfo.Type;
                    c.Content = questioninfo.Content;
                    for (int i = 0; i < questioninfo.Options.Count; i++)
                    {
                        c.Options.Add(new Option
                        {
                            OptionProperty = questioninfo.Options[i].OptionProperty,
                            IsCorrect      = questioninfo.Options[i].IsCorrect,
                            OptionId       = questioninfo.Options[i].OptionId
                        });
                    }
                    multipleQuestionList.Add(c);
                }
                paper.Questions.AddRange(trueOrFalseQuestionList);
                paper.Questions.AddRange(singleQuestionList);
                paper.Questions.AddRange(multipleQuestionList);
                DB.Papers.Add(paper);
                await DB.SaveChangesAsync();

                return(RedirectToAction("List"));
            }
            ;
            TempData["LastPostModel"] = paperInfo;
            return(RedirectToAction("Create"));
        }