public ActionResult DeleteQuizOp(int quizOptionSid)
        {
            if (!IsUserAuthenticated())
            {
                return(RedirectToLogin());
            }
            int courseSid = Convert.ToInt32(TempData.Peek("cid"));

            string message = string.Empty;

            if (!HasAccessToCourse(courseSid, out message))
            {
                return(RedirectToError(message));
            }

            int quizQuestionSid = Convert.ToInt32(TempData.Peek("quizQuestionSid"));

            using (var deleteOption = new QuizManager())
            {
                QuizOption quizOption = deleteOption.GetQuizOptionByQuizOptionSid(quizOptionSid, out message);
                if (deleteOption.DeleteQuizOption(quizOption, out message))
                {
                    SetTempDataMessage(Business.Common.Constants.ValueIsSuccessful("Quiz option has been deleted"));
                }
                else
                {
                    SetViewBagError(message);
                    SetBackURL("ManageOption?quizQuestionSid=" + quizQuestionSid);
                    return(View(quizOption));
                }
                return(RedirectToAction("ManageOption", new { quizQuestionSid = quizQuestionSid }));
            };
        }
Example #2
0
    private QuizOption[] GenerateQuizOptions(ResourceRequest request, QuizCategory category)
    {
        // Create the options
        QuizOption[] options = new QuizOption[3];

        // Get the usefulness of the request
        int usefulness = request.Usefulness;

        // The option at the usefulness level has full score
        options[usefulness] = new QuizOption(optionLabels[usefulness], 2);

        if (usefulness != 1)
        {
            // Middle option has score of 1
            options[1] = new QuizOption(optionLabels[1], 1);

            // The other usefulness option has score of 0
            usefulness          = (usefulness + 2) % 4;
            options[usefulness] = new QuizOption(optionLabels[usefulness], 0);
        }
        else
        {
            options[2] = new QuizOption(optionLabels[2], 1);
            options[0] = new QuizOption(optionLabels[0], 0);
        }

        return(options);
    }
        public ActionResult EditQuizOption(int quizOptionSid)
        {
            if (!IsUserAuthenticated())
            {
                return(RedirectToLogin());
            }
            int courseSid = Convert.ToInt32(TempData.Peek("cid"));

            string message = string.Empty;

            if (!HasAccessToCourse(courseSid, out message))
            {
                return(RedirectToError(message));
            }
            int quizQuestionSid = Convert.ToInt32(TempData.Peek("quizQuestionSid"));

            using (var getQuizOption = new QuizManager())
            {
                QuizOption quizOption = getQuizOption.GetQuizOptionByQuizOptionSid(quizOptionSid, out message);
                if (quizOption == null)
                {
                    SetViewBagError(message);
                }
                TempData["QuizOption"] = quizOption;
                SetBackURL("ManageOption?quizQuestionSid=" + quizQuestionSid);
                return(View(quizOption));
            };
        }
        public ActionResult CreateQuizOption(QuizOption quizOption)
        {
            if (!IsUserAuthenticated())
            {
                return(RedirectToLogin());
            }
            int    courseSid = Convert.ToInt32(TempData.Peek("cid"));
            string message   = string.Empty;

            if (!HasAccessToCourse(courseSid, out message))
            {
                return(RedirectToError(message));
            }

            int quizQuestionSid = Convert.ToInt32(TempData.Peek("quizQuestionSid"));

            using (var quizManager = new QuizManager())
            {
                if (quizManager.AddQuizOptionToQuizQuestion(quizOption, quizQuestionSid, out message) == null)
                {
                    SetViewBagError(message);
                    SetBackURL("ManageOption?quizQuestionSid=" + quizQuestionSid);
                    return(View());
                }
            }
            SetTempDataMessage(Business.Common.Constants.ValueIsSuccessful("Quiz Option has been created"));
            return(RedirectToAction("ManageOption", new { quizQuestionSid = quizQuestionSid }));
        }
        public async Task <ActionResult <QuizItem> > PostQuizItem([FromBody] QuizItem quizItem)
        {
            _context.QuizItem.Add(quizItem);
            await _context.SaveChangesAsync();

            if (quizItem.Answers != null && quizItem.Answers.Any())
            {
                foreach (var item in quizItem.Answers)
                {
                    var answer = new QuizAnswer
                    {
                        Answer     = item,
                        QuizItemId = quizItem.QuizItemId
                    };
                    _context.QuizAnswers.Add(answer);
                }
                await _context.SaveChangesAsync();
            }

            if (quizItem.Options != null && quizItem.Options.Any())
            {
                foreach (var item in quizItem.Options)
                {
                    var option = new QuizOption
                    {
                        Option     = item,
                        QuizItemId = quizItem.QuizItemId
                    };
                    _context.QuizOptions.Add(option);
                }
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction("GetQuizItem", new { id = quizItem.QuizItemId }, quizItem));
        }
Example #6
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent content)
    {
        SerializedProperty label  = property.FindPropertyRelative(nameof(label));
        SerializedProperty weight = property.FindPropertyRelative(nameof(weight));

        content = new GUIContent(QuizOption.ComputeDisplayName(label.stringValue, weight.intValue));
        EditorGUI.PropertyField(position, property, content, true);
    }
Example #7
0
 public bool DeleteQuizOption(QuizOption quizOption, out string message)
 {
     if (quizOption == null)
     {
         message = Constants.ValueIsEmpty(Constants.QuizOption);
         return(false);
     }
     return(DeleteQuizOption(quizOption.Sid, out message));
 }
        public async Task <IActionResult> PutQuizItem([FromBody] QuizItem quizItem)
        {
            var dbItem = _context.QuizItem.Find(quizItem.QuizItemId);

            _context.Entry(dbItem).State = EntityState.Detached;
            if (dbItem == null)
            {
                return(BadRequest());
            }
            _context.Entry(quizItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                if (quizItem.Answers != null && quizItem.Answers.Any())
                {
                    var oldAnswers = _context.QuizAnswers.Where(a => a.QuizItemId == quizItem.QuizItemId);
                    _context.QuizAnswers.RemoveRange(oldAnswers);
                    _context.SaveChanges();
                    foreach (var item in quizItem.Answers)
                    {
                        var answer = new QuizAnswer
                        {
                            Answer     = item,
                            QuizItemId = quizItem.QuizItemId
                        };
                        _context.QuizAnswers.Add(answer);
                    }
                    await _context.SaveChangesAsync();
                }

                if (quizItem.Options != null && quizItem.Options.Any())
                {
                    var oldOptions = _context.QuizOptions.Where(a => a.QuizItemId == quizItem.QuizItemId);
                    _context.QuizOptions.RemoveRange(oldOptions);
                    _context.SaveChanges();
                    foreach (var item in quizItem.Options)
                    {
                        var option = new QuizOption
                        {
                            Option     = item,
                            QuizItemId = quizItem.QuizItemId
                        };
                        _context.QuizOptions.Add(option);
                    }
                    await _context.SaveChangesAsync();
                }
            }

            catch (DbUpdateConcurrencyException)
            {
            }

            return(Ok("Updated successfully!"));
        }
Example #9
0
    public void DisplayAnswer(QuizInstance quiz, int questionIndex)
    {
        if (questionIndex >= 0 && questionIndex < quiz.RuntimeTemplate.Questions.Length)
        {
            // Store quiz question for easy access
            QuizQuestion question    = quiz.RuntimeTemplate.Questions[questionIndex];
            QuizOption   answer      = quiz.GetAnswer(questionIndex);
            int          answerIndex = quiz.Answers[questionIndex];

            // Setup question text
            questionText.text = $"Question {questionIndex + 1}: {question.Question}";

            // Setup answer text
            answerText.text = $"\t";

            // Add text for each answer, highlighting the picked answer
            for (int i = 0; i < question.Options.Length; i++)
            {
                QuizOption option = question.Options[i];

                // Give the answer a bold white color
                if (option == answer)
                {
                    answerText.text += $"<color=white>* {option.Label}</color>";
                }
                // Use the normal label for other options
                else
                {
                    answerText.text += option.Label;
                }

                // Add endline and tab after each option except the last
                if (i < question.Options.Length - 1)
                {
                    answerText.text += "\n\t";
                }
            }

            // Compute the relative grade, and give flavor text for different grade levels
            if (question.RelativeGrade(answerIndex) > 0.6f)
            {
                gradeText.text = "<color=green>Consistent with existing research!</color>";
            }
            else
            {
                gradeText.text = "<color=red>Not consistent with existing research...</color>";
            }
        }
    }
Example #10
0
 public QuizOption AddQuizOptionToQuizQuestion(QuizOption quizOption, int quizQuestionSid, out string message)
 {
     if (quizOption == null)
     {
         message = Constants.ValueIsEmpty(Constants.QuizOption);
         return(null);
     }
     if (quizQuestionSid == 0)
     {
         message = Constants.ValueIsEmpty(Constants.QuizQuestion);
         return(null);
     }
     if (string.IsNullOrEmpty(quizOption.Title) || string.IsNullOrEmpty(quizOption.Title.Trim()))
     {
         message = Constants.PleaseFillInAllRequiredFields();
         //message = Constants.PleaseEnterValue(Constants.OptionTitle);
         return(null);
     }
     try
     {
         using (var unitOfWork = new UnitOfWork(new ActiveLearningContext()))
         {
             using (TransactionScope scope = new TransactionScope())
             {
                 quizOption.CreateDT        = DateTime.Now;
                 quizOption.QuizQuestionSid = quizQuestionSid;
                 unitOfWork.QuizOptions.Add(quizOption);
                 unitOfWork.Complete();
                 scope.Complete();
             }
             message = string.Empty;
             return(quizOption);
         }
     }
     catch (Exception ex)
     {
         ExceptionLog(ex);
         message = Constants.OperationFailedDuringAddingValue(Constants.QuizOption);
         return(null);
     }
 }
Example #11
0
    public static ItemizedQuizScore ComputeItemizedScore(QuizRuntimeTemplate runtimeTemplate, int[] answers)
    {
        ItemizedQuizScore itemizedScore = new ItemizedQuizScore();

        for (int i = 0; i < runtimeTemplate.Questions.Length; i++)
        {
            // Get the current question and answer
            QuizQuestion question = runtimeTemplate.Questions[i];
            int          answer   = answers[i];

            // If the answer is within range of the options
            // then add the option's weight to the total score
            if (answer >= 0 && answer < question.Options.Length)
            {
                QuizOption option       = question.Options[answer];
                int        currentScore = itemizedScore.GetOrElse(question.Category, 0);
                itemizedScore.Set(question.Category, currentScore + option.Weight);
            }
        }

        return(itemizedScore);
    }
        public ActionResult updateQuizOpt(QuizOption quizOption)
        {
            if (!IsUserAuthenticated())
            {
                return(RedirectToLogin());
            }

            int courseSid = Convert.ToInt32(TempData.Peek("cid"));

            string message = string.Empty;

            if (!HasAccessToCourse(courseSid, out message))
            {
                return(RedirectToError(message));
            }

            int quizQuestionSid = Convert.ToInt32(TempData.Peek("quizQuestionSid"));

            var quizOptToUpdate = TempData.Peek("QuizOption") as QuizOption;

            quizOptToUpdate.Title = quizOption.Title;

            quizOptToUpdate.IsCorrect = quizOption.IsCorrect;

            using (var updateOpt = new QuizManager())
            {
                if (updateOpt.UpdateQuizOption(quizOptToUpdate, out message))
                {
                    SetTempDataMessage(Business.Common.Constants.ValueIsSuccessful("Quiz Option has been updated"));
                }
                else
                {
                    SetViewBagError(message);
                    SetBackURL("ManageOption?quizQuestionSid=" + quizQuestionSid);
                    return(View(quizOptToUpdate));
                }
                return(RedirectToAction("ManageOption", new { quizQuestionSid = quizQuestionSid }));
            }
        }
Example #13
0
        public bool UpdateQuizOption(QuizOption quizOption, out string message)
        {
            if (quizOption == null || quizOption.Sid == 0)
            {
                message = Constants.ValueIsEmpty(Constants.QuizOption);
                return(false);
            }
            if (string.IsNullOrEmpty(quizOption.Title) || string.IsNullOrEmpty(quizOption.Title.Trim()))
            {
                message = Constants.PleaseFillInAllRequiredFields();
                //message = Constants.PleaseEnterValue(Constants.OptionTitle);
                return(false);
            }
            try
            {
                using (var unitOfWork = new UnitOfWork(new ActiveLearningContext()))
                {
                    var quizOptionToUpdate = unitOfWork.QuizOptions.GetAll().Where(a => a.Sid == quizOption.Sid).FirstOrDefault();
                    Util.CopyNonNullProperty(quizOption, quizOptionToUpdate);
                    quizOptionToUpdate.UpdateDT = DateTime.Now;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        unitOfWork.Complete();
                        scope.Complete();
                    }
                    message = string.Empty;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ExceptionLog(ex);
                message = Constants.OperationFailedDuringUpdatingValue(Constants.QuizOption);
                return(false);
            }
        }
Example #14
0
    public NPCConversation Create(DialogueManager dialogueManager)
    {
        // Build a new quiz. This will result in regenerating new questions from any randomized pools
        GenerateQuizInstance();

        // Create the callback that is called after any option is answered
        UnityAction OptionSelectedFunctor(int questionIndex, int optionIndex)
        {
            return(() => currentQuiz.AnswerQuestion(questionIndex, optionIndex));
        }

        // Say the conversation that corresponds to the grade that the player got on the quiz
        void SayResponse()
        {
            // Destroy any previous response
            if (currentResponse)
            {
                Destroy(currentResponse);
            }
            // Instantiate a new response
            currentResponse = response.Get(CurrentQuiz.Grade).InstantiateAndSay();

            // If we should requiz when we fail, then we must say the quiz after the response
            if (requizOnFail && CurrentQuiz.Grade != QuizGrade.Excellent)
            {
                SayQuizConversationNext();
            }
            // If we will not requiz, then invoke my conversation ended event when this conversation is done
            else
            {
                // Set the quiz on the reports data to the quiz that we just finished
                GameManager.Instance.NotebookUI.Data.Reports.SetQuiz(LevelID.Current(), currentQuiz);

                // Invoke the quiz conversation ended event when the response is over
                currentResponse.OnConversationEnded(onConversationEnded.Invoke);
            }
        }

        // Try to get an npc conversation. If it exists, destroy it and add a new one
        NPCConversation conversation = gameObject.GetComponent <NPCConversation>();

        if (conversation)
        {
#if UNITY_EDITOR
            DestroyImmediate(conversation);
#else
            Destroy(conversation);
#endif
        }
        conversation = gameObject.AddComponent <NPCConversation>();

        // Create the conversation to be edited here in the code
        EditableConversation editableConversation = new EditableConversation();
        EditableSpeechNode   previousSpeechNode   = null;

        // A list of all nodes added to the conversation
        List <EditableConversationNode> nodes = new List <EditableConversationNode>();

        // Loop over every question and add speech and option nodes for each
        for (int i = 0; i < currentQuiz.RuntimeTemplate.Questions.Length; i++)
        {
            // Cache the current question
            QuizQuestion question = currentQuiz.RuntimeTemplate.Questions[i];

            // Create a new speech node
            EditableSpeechNode currentSpeechNode = CreateSpeechNode(conversation, editableConversation, question.Question, 0, i * 300, i == 0, null);
            nodes.Add(currentSpeechNode);

            // If a previous speech node exists, then make the options on the previous node
            // point to the speech on the current node
            if (previousSpeechNode != null)
            {
                foreach (EditableOptionNode option in previousSpeechNode.Options)
                {
                    option.Speech.SetSpeech(currentSpeechNode);
                }
            }

            // Add an option node for each quiz option
            for (int j = 0; j < question.Options.Length; j++)
            {
                // Get the current option
                QuizOption option = question.Options[j];

                // Create a new option node with the same label as the quiz option
                EditableOptionNode optionNode = CreateOptionNode(conversation, editableConversation, option.Label, j * 220, (i * 300) + 100);
                currentSpeechNode.AddOption(optionNode);
                nodes.Add(optionNode);

                // Create a dummy node. It is used to invoke events
                UnityAction        optionCallback = OptionSelectedFunctor(i, j);
                EditableSpeechNode dummyNode      = CreateSpeechNode(conversation, editableConversation, string.Empty, j * 220, (i * 300) + 200, false, optionCallback);
                nodes.Add(dummyNode);

                // Make the dummy node advance immediately
                dummyNode.AdvanceDialogueAutomatically   = true;
                dummyNode.AutoAdvanceShouldDisplayOption = false;
                dummyNode.TimeUntilAdvance = 0f;

                // Make the option node point to the dummy node
                optionNode.SetSpeech(dummyNode);
            }

            // Update previous speech node to current before resuming
            previousSpeechNode = currentSpeechNode;
        }

        // Create the end of quiz node
        EditableSpeechNode endOfQuiz = CreateSpeechNode(conversation, editableConversation, endOfQuizText, 0, currentQuiz.RuntimeTemplate.Questions.Length * 300, false, SayResponse);
        nodes.Add(endOfQuiz);

        // If a previous speech node exists,
        // then make its options point to the end of quiz node
        if (previousSpeechNode != null)
        {
            foreach (EditableOptionNode option in previousSpeechNode.Options)
            {
                option.Speech.SetSpeech(endOfQuiz);
            }
        }

        // Have all the nodes register their UIDs (whatever the frick THAT means)
        foreach (EditableConversationNode node in nodes)
        {
            node.RegisterUIDs();
        }

        // Serialize the editable conversation back into the NPCConversation and return the result
        conversation.RuntimeSave(editableConversation);
        return(conversation);
    }