/// <summary>
        /// Creates new instance of Question element in database.
        /// </summary>
        /// <param name="questionElement"></param>
        /// <returns></returns>
        public async Task <ServiceActionResult <QuestionElementActionStatus, QuestionElement> > Create(
            QuestionElement questionElement)
        {
            var answerSetValidationResult =
                await this.ValidateAnswerSet(questionElement.AnswerSetId, questionElement);

            if (answerSetValidationResult != QuestionElementActionStatus.Success)
            {
                return(new ServiceActionResult <QuestionElementActionStatus, QuestionElement>(answerSetValidationResult));
            }

            questionElement.Type = ElementType.Question;

            if (!await this.careElementContext.IsCIUser())
            {
                questionElement.InternalId = null;
            }

            await this.UpdateInternalValues(questionElement.QuestionElementToSelectionAnswerChoices);

            await this.UpdateInternalValues(questionElement.QuestionElementToScaleAnswerChoices);

            this.questionElementRepository.Insert(questionElement);
            await this.unitOfWork.SaveAsync();

            return
                (new ServiceActionResult <QuestionElementActionStatus, QuestionElement>(
                     QuestionElementActionStatus.Success, questionElement));
        }
        public QuestionElement addUserQuestion()
        {
            Console.WriteLine("Quizelement erstellen");
            Console.WriteLine("Bitte gib eine Frage ein");
            Console.WriteLine("> ");
            var question = Console.ReadLine();

            Console.WriteLine("Bitte gib die richtige Antwort ein");
            var correctAnswer = Console.ReadLine();

            Console.WriteLine("Bitte gib eine falsche Antwort ein");
            var           wrongAnswer  = Console.ReadLine();
            List <string> wrongAnswers = new List <string>();

            wrongAnswers.Add(wrongAnswer);
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Bitte gib wieder eine falsche Antwort ein oder beende das Programm, indem du die: beenden schreibst.");
                var text = Console.ReadLine();
                if (text == "beenden")
                {
                    break;
                }
                else
                {
                    wrongAnswers.Add(text);
                }
            }
            QuestionElement quizelemente = new QuestionElement(question, correctAnswer, wrongAnswers);

            questionelement.Add(quizelemente);
            return(quizelemente);
        }
Example #3
0
    public void LoadQuestion(Question question)
    {
        CurrentQuestion = question;
        //delete possible old elements
        DeleteQuestion();
        //set question Text
        QuestionTask.text = CurrentQuestion.QuestionTask;
        //set question Elements
        for (int i = 0; i < CurrentQuestion.GetQuestionCount(); i++)
        {
            GameObject QuestionElement;
            if (CurrentQuestion.QuestionType == QuestionTypes.CHECKBOX)
            {
                QuestionElement = Instantiate(CheckboxElementPrefab);
            }
            else if (CurrentQuestion.QuestionType == QuestionTypes.RADIO_BUTTON)
            {
                QuestionElement = Instantiate(RadioButtonElementPrefab);
            }
            else
            {
                QuestionElement = Instantiate(TextInputElementPrefab);
            }

            AbstractQuestionElementBehaviour elementBehaviour = QuestionElement.GetComponent <AbstractQuestionElementBehaviour>();
            elementBehaviour.element = CurrentQuestion.GetQuestionElement(i);
            elementBehaviour.CurrentQuestionBehaviour = this;
            QuestionElementBehaviours.Add(elementBehaviour);
            //QuestionElement.transform.SetParent(QuestionElementsContainer, false);
        }

        OrientationHelper.question = CurrentQuestion;
        OrientationHelper.SetBehaviours(QuestionElementBehaviours);
    }
Example #4
0
        public void answerQuestion(QuestionElement questionelement)
        {
            int           sizeOfList = questionelement.wrongAnswers.Count();
            List <string> answers    = new List <string>();

            for (int i = 0; i < sizeOfList; i++)
            {
                answers.Add(questionelement.wrongAnswers[i]);
            }
            answers.Add(questionelement.correctAnswer);
            Console.WriteLine("Beantworte folgende Frage: ");
            Console.WriteLine(questionelement.question);
            Random rng       = new Random();
            var    something = answers.OrderBy(a => rng.Next());

            answers = something.ToList <String>();
            writeIt(answers);
            Console.WriteLine("Bitte schreiben Sie die korrekte Antwort hin: ");
            Console.Write(">");
            var text = Console.ReadLine();

            if (text == questionelement.correctAnswer)
            {
                points += 1;
                Console.WriteLine("\n Diese Antwort ist korrekt. \n");
            }
            else
            {
                Console.WriteLine("\n Diese Antwort ist falsch. Die richtige Antwort lautet:" + questionelement.correctAnswer + "\n");
            }
        }
Example #5
0
        public static void menu()
        {
            Console.WriteLine("Bitte wählen Sie zwischen: ");
            Console.WriteLine("1. eine neue Frage hinzufügen");
            Console.WriteLine("2. eine Frage beantworten");
            Console.WriteLine("3. Das Spiel verlassen");
            var number = Console.ReadLine();
            int x      = Int32.Parse(number);

            if (x == 1)
            {
                questionelement = addeUserQuestion.addUserQuestion();
                question.Add(questionelement);
                menu();
            }
            else if (x == 2)
            {
                int    sizeOfList     = question.Count();
                Random random         = new Random();
                int    questionNumber = random.Next(0, sizeOfList);
                answerQuestion.answerQuestion(question[questionNumber]);
                question.RemoveAt(questionNumber);
                menu();
            }
            else
            {
                Console.WriteLine("Die Eingabe war ungültig, bitte versuchen Sie es erneut");
                menu();
            }
        }
    private QuestionElement CreateQuestion(int type)
    {
        QuestionElement instance = Instantiate(questionPrefabs[type]);

        instance.transform.SetParent(questionsContainer);
        instance.Question.index = questionElementInstances.Count;
        questionElementInstances.Add(instance);
        return(instance);
    }
Example #7
0
 private IEnumerator PlayVoice(QuestionElement element)
 {
     if (element.Voice == null)
     {
         yield break;
     }
     _audioSource.clip = element.Voice;
     _audioSource.Play();
     yield return(new WaitForSeconds(element.Voice.length));
 }
        /// <summary>
        /// Updates data of question element.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="questionElementId">The question element identifier.</param>
        /// <param name="questionElement">The question element.</param>
        /// <returns></returns>
        public async Task <ServiceActionResult <QuestionElementActionStatus, QuestionElement> > Update(
            int customerId,
            Guid questionElementId,
            QuestionElement questionElement
            )
        {
            var dbEntity = await Get(customerId, questionElementId);

            if (dbEntity == null)
            {
                return
                    (new ServiceActionResult <QuestionElementActionStatus, QuestionElement>(
                         QuestionElementActionStatus.NotFound));
            }

            questionElement.CustomerId = customerId;
            questionElement.Id         = questionElementId;

            var answerSetValidationResult =
                await this.ValidateAnswerSet(questionElement.AnswerSetId, questionElement);

            if (answerSetValidationResult != QuestionElementActionStatus.Success)
            {
                return(new ServiceActionResult <QuestionElementActionStatus, QuestionElement>(answerSetValidationResult));
            }

            await this.UpdateInternalValues(dbEntity.QuestionElementToSelectionAnswerChoices,
                                            questionElement.QuestionElementToSelectionAnswerChoices);

            await this.UpdateInternalValues(dbEntity.QuestionElementToScaleAnswerChoices,
                                            questionElement.QuestionElementToScaleAnswerChoices);

            dbEntity.QuestionElementToSelectionAnswerChoices.Clear();
            this.questionElementScaleAnswerChoiceRepository.DeleteRange(dbEntity.QuestionElementToScaleAnswerChoices);

            dbEntity.QuestionElementToSelectionAnswerChoices = questionElement.QuestionElementToSelectionAnswerChoices;
            dbEntity.QuestionElementToScaleAnswerChoices     = questionElement.QuestionElementToScaleAnswerChoices;
            dbEntity.AnswerSetId = questionElement.AnswerSetId;
            dbEntity.ExternalId  = questionElement.ExternalId;
            dbEntity.Tags.UpdateWith(questionElement.Tags);
            dbEntity.AddOrUpdateString(questionElement.LocalizedStrings.First());

            if (await this.careElementContext.IsCIUser())
            {
                dbEntity.InternalId = questionElement.InternalId;
            }

            questionElementRepository.Update(dbEntity);
            await unitOfWork.SaveAsync();

            return
                (new ServiceActionResult <QuestionElementActionStatus, QuestionElement>(
                     QuestionElementActionStatus.Success, dbEntity));
        }
    IEnumerator WaitAndUpload(QuestionElement item)
    {
        item.UploadScreenShot();
        while (!item.UploadComplete())
        {
            yield return(null);
        }
        string json = JsonUtility.ToJson(item.Question);

        new GameSparkRequests("SaveQuestion").Add("index", item.Question.index).Add("code", item.Question.code).Add("data", json).Add("answer", item.Question.correctIndex).Add("date", date.text).Request(SaveQuestionsSuccess);
    }
        /// <summary>
        /// Includes new or updates existed localized string.
        /// </summary>
        /// <param name="?"></param>
        public static void AddOrUpdateString(this QuestionElement dbEntity, QuestionElementString localizedString)
        {
            var existedString =
                dbEntity.LocalizedStrings.FirstOrDefault(s => s.Language.Equals(localizedString.Language));

            if (existedString == null)
            {
                dbEntity.LocalizedStrings.Add(localizedString);
            }
            else
            {
                existedString.UpdateWith(localizedString);
            }
        }
Example #11
0
 /// <summary>
 /// Initializes ids of answer choices in question element entity.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="answerChoices"></param>
 private void MapAnswerChoiceIds(QuestionElement entity, IEnumerable <AnswerChoiceIdDto> answerChoices)
 {
     foreach (var answerChoiceIdDto in answerChoices)
     {
         if (answerChoiceIdDto.Id.HasValue)
         {
             entity.QuestionElementToSelectionAnswerChoices.Add(
                 Mapper.Map <QuestionElementToSelectionAnswerChoice>(answerChoiceIdDto));
         }
         else
         {
             entity.QuestionElementToScaleAnswerChoices.Add(
                 Mapper.Map <QuestionElementToScaleAnswerChoice>(answerChoiceIdDto));
         }
     }
 }
    private void GotQuestionsCallback(string str)
    {
        ResetQuestions();
        GSListResult result = JsonUtility.FromJson <GSListResult>(str);

        foreach (var item in result.scriptData.result)
        {
            Question qn = JsonUtility.FromJson <Question>(item);
            questions.Add(qn);
        }
        questions = questions.OrderBy(a => a.index).ToList();
        foreach (var item in questions)
        {
            QuestionElement instance = CreateQuestion((int)item.type);
            instance.Setup(item);
        }
    }
        /// <summary>
        /// Validates that answerset with specified id can be used for provided question.
        /// </summary>
        /// <returns></returns>
        private async Task <QuestionElementActionStatus> ValidateAnswerSet(Guid answerSetId,
                                                                           QuestionElement questionElement)
        {
            var answerSet = await this.GetAnswerSet(answerSetId);

            if (answerSet == null)
            {
                return(QuestionElementActionStatus.AnswerSetNotExists);
            }

            if (answerSet.CustomerId != careElementContext.CustomerId)
            {
                return(QuestionElementActionStatus.AnswerSetCannotBeUsed);
            }

            if (answerSet.Type == AnswerSetType.Scale)
            {
                var scaleAnswerSet = answerSet as ScaleAnswerSet;

                if (questionElement.QuestionElementToSelectionAnswerChoices.Any())
                {
                    return(QuestionElementActionStatus.AnswerChoiceCannotBeUsed);
                }

                if (questionElement.QuestionElementToScaleAnswerChoices.Any(
                        c => c.Value > scaleAnswerSet.HighValue || c.Value < scaleAnswerSet.LowValue))
                {
                    return(QuestionElementActionStatus.InvalidScaleValueRange);
                }
            }
            else if (answerSet.Type == AnswerSetType.Selection)
            {
                var selectionAnswerSet = answerSet as SelectionAnswerSet;

                if (questionElement.QuestionElementToScaleAnswerChoices.Any() ||
                    questionElement.QuestionElementToSelectionAnswerChoices.Any(
                        c => selectionAnswerSet.SelectionAnswerChoices.All(a => a.Id != c.SelectionAnswerChoiceId)))
                {
                    return(QuestionElementActionStatus.AnswerChoiceCannotBeUsed);
                }
            }

            return(QuestionElementActionStatus.Success);
        }
 public void RemoveQuestion(QuestionElement obj)
 {
     questionElementInstances.Remove(obj);
     Destroy(obj.gameObject);
 }
 /// <summary>
 /// Resolves the core.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <returns></returns>
 protected override IEnumerable <AnswerChoiceIdDto> ResolveCore(QuestionElement source)
 {
     return(source.AnswerSet.Type == AnswerSetType.Scale
         ? source.QuestionElementToScaleAnswerChoices.Select(Mapper.Map <AnswerChoiceIdDto>)
         : source.QuestionElementToSelectionAnswerChoices.Select(Mapper.Map <AnswerChoiceIdDto>));
 }