public void AddTextAnswer(TextAnswer textAnswer)
 {
     using (var context = new FinalProjectDBEntities1())
     {
         context.TextAnswers.Add(textAnswer);
     }
 }
Ejemplo n.º 2
0
        private void GetTextResult(Question _question, TextAnswer textAnswer, ref uint count)
        {
            var question = _question as TextQuestion;

            if (!String.IsNullOrEmpty(textAnswer.Text) && !String.IsNullOrEmpty(question.TextRightAnswer))
            {
                if (String.Equals(textAnswer.Text, question.TextRightAnswer, StringComparison.CurrentCultureIgnoreCase))
                {
                    textAnswer.Score = question.Score;
                    count++;
                    textAnswer.Result = AnswerResult.Right;
                }
                else
                {
                    textAnswer.Result = AnswerResult.Wrong;
                    textAnswer.Score  = 0;
                }
            }
            else
            {
                textAnswer.Result = null;
                textAnswer.Text   = "";
                textAnswer.Score  = 0;
            }
            _context.TextAnswers.Update(textAnswer);
        }
 public void DeleteTextAnswer(int Id)
 {
     using (var context = new FinalProjectDBEntities1())
     {
         TextAnswer textanswer = context.TextAnswers.Find(Id);
         context.TextAnswers.Remove(textanswer);
     }
 }
        private static TextAnswer GenerateTextAnswer(FormCollection collection, Evaluation evaluation, Question question, string aux)
        {
            TextAnswer t = new TextAnswer();

            t.CreationDate  = DateTime.Now;
            t.Evaluation_Id = evaluation.Id;
            t.Question_Id   = question.Id;
            t.Text          = collection["q[" + question.Id + aux + "]"];
            return(t);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a Text answer to the group represented by the GroupID
        /// </summary>
        /// <param name="GroupID"></param>
        /// <param name="iQuestionID"></param>
        /// <param name="AnswerText"></param>
        /// <returns></returns>
        public bool AddAnswerToRecord(long recordID, long questionID, string answerText)
        {
            Record record    = RecordFromID(recordID);
            Answer newAnswer = new TextAnswer();

            newAnswer.RecordID           = recordID;
            newAnswer.QuestionID         = questionID;
            ((TextAnswer)newAnswer).Text = answerText;
            record.AddAnswer(newAnswer);
            return(true);
        }
Ejemplo n.º 6
0
        static Test<string, object> GetTest()
        {
            var test = new Test<string, object>("Test");

            var question =
                new StringQuestion("В каком случае в одной области видимости можно объявить два делегата с одним именем?",
                             ComplexityLevel.Hard);
            question.AddAnswer(new Answer<string>("Если у делегатов различное количество параметров.", false));
            question.AddAnswer(new Answer<string>("Ни в каком.", true));
            var textAnswer = new TextAnswer("Answer", false);
            question.AddAnswer(textAnswer);
            test.AddQuestion(question);

            question = new StringQuestion("Какое утверждение об интерфейсах (Ин.) справедливо?", new Range<int>(2, 2),
                                    ComplexityLevel.Hard);
            question.AddAnswer(new Answer<string>("Ин. поддерживают множественное наследование.", true));
            question.AddAnswer(new Answer<string>("Ин. могут содержать поля.", false));
            question.AddAnswer(new Answer<string>("Ин. могут содержать конструкторы.", false));
            question.AddAnswer(new Answer<string>("Ин. могут содержать cвойства, методы, события", true));
            test.AddQuestion(question);

            question = new StringQuestion("Ключевое слово sealed применимо к...", ComplexityLevel.Easy);
            question.AddAnswer(new Answer<string>("Полям.", false));
            question.AddAnswer(new Answer<string>("Интерфейсам.", false));
            question.AddAnswer(new Answer<string>("Методам.", true));
            test.AddQuestion(question);

            question = new StringQuestion("Что является особенностью пользовательских структур?", ComplexityLevel.Easy);
            question.AddAnswer(new Answer<string>("Структуры не поддерживают наследование.", true));
            question.AddAnswer(new Answer<string>("Структура не может содержать событий.", false));
            test.AddQuestion(question);

            question =
                new StringQuestion(
                    "Какое ключевое слово используется в производном классе для вызова конструктора класса-предка?",
                    ComplexityLevel.Easy);
            question.AddAnswer(new Answer<string>("class", false));
            question.AddAnswer(new Answer<string>("base", true));
            question.AddAnswer(new Answer<string>("this", false));
            test.AddQuestion(question);

            question = new StringQuestion("В групповой делегат объединили 3 функции и произвели вызов. Что будет получено?");
            question.AddAnswer(new Answer<string>("Исключительная ситуация.", false));
            question.AddAnswer(new Answer<string>("Массив из трех значений.", false));
            question.AddAnswer(new Answer<string>("Значение последней функции в цепочке.", true));
            test.AddQuestion(question);

            return test;
        }
Ejemplo n.º 7
0
        private async Task SaveTextAnswers(ICollection <TextQuestionDTO> textQuestions, Guid token)
        {
            foreach (var item in textQuestions)
            {
                if (item.Answer != null)
                {
                    var answer = new TextAnswer();
                    answer.Answer          = item.Answer;
                    answer.CorelationToken = token;
                    answer.TextQuestionId  = item.Id;

                    await this.dbcontext.TextAnswers.AddAsync(answer);
                }
            }
        }
Ejemplo n.º 8
0
        public static TextAnswerDto ToTextAnswerDto(this TextAnswer textAnswer)
        {
            if (textAnswer == null)
            {
                return(null);
            }

            var textAnswerDto = new TextAnswerDto
            {
                Id        = textAnswer.Id,
                Textbox   = textAnswer.Textbox,
                IsCorrect = textAnswer.IsCorrect.Value
            };

            return(textAnswerDto);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds the answer to the corresponding (non-lookup) question
        /// </summary>
        /// <param name="iQuestionID"></param>
        /// <param name="AnswerText"></param>
        /// <returns></returns>
        public bool AddAnswer(long questionID, string AnswerText, long answerID)
        {
            bool addOK = false;

            try
            {
                TextAnswer newAnswer = new TextAnswer();
                newAnswer.QuestionID = questionID;
                newAnswer.Text       = AnswerText;
                newAnswer.AnswerID   = answerID;
                AddAnswer(newAnswer);
                addOK = true;
            }
            catch (System.Exception ex)
            {
                _errors.Add(ex);
                _last_error = ex;
                addOK       = false;
            }

            return(addOK);
        }
 private void Update()
 {
     if (_model != null)
     {
         _questions.Clear();
         foreach (var question in _model.Questions)
         {
             if (question is TextQuestion)
             {
                 var answer = new TextAnswer();
                 _questions.Add(new TextAnswerViewModel((TextQuestion)question, answer));
                 _filledModel.Answers.Add(answer);
             }
             if (question is ImgChoiceQuestion)
             {
                 var answer = new SingleChoiceAnswer();
                 _questions.Add(new ImgChoiceAnswerViewModel((ImgChoiceQuestion)question, answer));
                 _filledModel.Answers.Add(answer);
             }
         }
     }
     OnNotifyPropertyChanged("Questions");
 }
Ejemplo n.º 11
0
        public Question toQuestio()
        {
            Question retQuestion = new Question();

            retQuestion.ID           = this.ID;
            retQuestion.Picture      = this.Picture;
            retQuestion.Points       = this.Points;
            retQuestion.QuestionText = this.QuestionText;
            foreach (editAnswer answerModel in this.Answers)
            {
                Answer tempAnswer = null;
                if (answerModel.type.ToLower().Contains("region"))
                {
                    tempAnswer = new RegionAnswer(answerModel.x1, answerModel.x2, answerModel.y1, answerModel.y2, answerModel.IsCorrect);
                }
                else if (answerModel.type.ToLower().Contains("text"))
                {
                    tempAnswer = new TextAnswer(answerModel.text, answerModel.IsCorrect);
                }
                //tempAnswer.ID = answerModel.ID;
                retQuestion.Answers.Add(tempAnswer);
            }
            return(retQuestion);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Method which focuses <see cref="TextAnswer"/> when <see cref="Window"/> is rendered.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Window_ContentRendered(object sender, EventArgs e)
 {
     TextAnswer.SelectAll();
     TextAnswer.Focus();
 }
        private static void InsertTextAnswer(FormCollection collection, Evaluation evaluation, Question question, string aux)
        {
            TextAnswer t = GenerateTextAnswer(collection, evaluation, question, aux);

            new TextAnswersServices().Add(t);
        }
Ejemplo n.º 14
0
 public TextAnswerViewModel(TextQuestion question, TextAnswer answer): base(question)
 {
     _answerModel = answer;
 }
Ejemplo n.º 15
0
        public async Task <IActionResult> Start(int testResultId, ErrorViewModel model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var testResult = await _context.TestResults
                             .Include(tr => tr.Test)
                             .ThenInclude(t => t.Questions)
                             .SingleAsync(t => t.Id == testResultId);

            if (testResult == null)
            {
                return(NotFound());
            }
            if (!testResult.Test.IsEnabled)
            {
                return(Forbid());
            }
            var questions = testResult.Test.Questions.Where(q => !q.IsDeleted).ToList();

            if (questions.Count() == 0)
            {
                return(NotFound());
            }
            if (_context.Answers.Any(a => a.TestResult == testResult))
            {
                return(RedirectToAction("Answer", "Answer",
                                        new
                {
                    testResultId = testResult.Id,
                    answerId = _context.Answers.Where(a => a.TestResult == testResult)
                               .SingleOrDefault(a => a.Order == 1).Id
                }));
            }
            var    answers = new List <Answer>();
            Answer answer  = null;

            if (testResult.Test.Count != 0 && testResult.Test.Count < questions.Count && testResult.Test.Shuffled)
            {
                var order = new ushort[testResult.Test.Count];
                for (var i = 0; i < order.Length; i++)
                {
                    order[i] = (ushort)(i + 1);
                }
                if (testResult.Test.Shuffled)
                {
                    Shuffle(order);
                }
                var j = 0;
                Shuffle(questions);
                for (var k = 0; k < order.Length; k++)
                {
                    var question = questions[k];
                    switch (question.QuestionType)
                    {
                    case "SingleChoiceQuestion":
                        answer = new SingleChoiceAnswer();
                        break;

                    case "MultiChoiceQuestion":
                        answer = new MultiChoiceAnswer();
                        break;

                    case "TextQuestion":
                        answer = new TextAnswer();
                        break;

                    case "DragAndDropQuestion":
                        answer = new DragAndDropAnswer();
                        break;

                    case "CodeQuestion":
                        answer = new CodeAnswer();
                        break;
                    }

                    if (answer == null)
                    {
                        throw new NullReferenceException();
                    }
                    answer.Result     = null;
                    answer.Question   = question;
                    answer.Score      = 0;
                    answer.TestResult = testResult;
                    answer.Order      = order[j++];
                    await _context.Answers.AddAsync(answer);

                    answers.Add(answer);
                    await _context.SaveChangesAsync();
                }
            }
            else
            {
                var order = new ushort[questions.Count()];
                for (var i = 0; i < order.Length; i++)
                {
                    order[i] = (ushort)(i + 1);
                }
                if (testResult.Test.Shuffled)
                {
                    Shuffle(order);
                }
                var j = 0;
                foreach (var question in questions)
                {
                    switch (question.QuestionType)
                    {
                    case "SingleChoiceQuestion":
                        answer = new SingleChoiceAnswer();
                        break;

                    case "MultiChoiceQuestion":
                        answer = new MultiChoiceAnswer();
                        break;

                    case "TextQuestion":
                        answer = new TextAnswer();
                        break;

                    case "DragAndDropQuestion":
                        answer = new DragAndDropAnswer();
                        break;

                    case "CodeQuestion":
                        answer = new CodeAnswer();
                        break;
                    }

                    if (answer == null)
                    {
                        throw new NullReferenceException();
                    }
                    answer.Question   = question;
                    answer.Score      = 0;
                    answer.TestResult = testResult;
                    answer.Order      = order[j++];
                    await _context.Answers.AddAsync(answer);

                    answers.Add(answer);
                    await _context.SaveChangesAsync();
                }
            }
            testResult.StartedOn = DateTime.UtcNow;
            _context.TestResults.Update(testResult);
            await _context.SaveChangesAsync();

            // TODO: redirect to first answer (question)
            //throw new NotImplementedException();
            return(RedirectToAction("Answer", "Answer",
                                    new { testResultId = testResult.Id, answerId = answers.SingleOrDefault(a => a.Order == 1).Id }));
        }
Ejemplo n.º 16
0
        private void StartTest(User user, TestResult testResult, Test test)
        {
            var    answers   = new List <Answer>();
            Answer answer    = null;
            var    questions = testResult.Test.Questions.Where(q => !q.IsDeleted).ToList();

            testResult.TotalQuestions = (uint)questions.Count;
            if (test.Count != 0 && test.Count < test.Questions.Count && testResult.Test.Shuffled)
            {
                var order = new ushort[testResult.Test.Count];
                for (var i = 0; i < order.Length; i++)
                {
                    order[i] = (ushort)(i + 1);
                }

                var j = 0;
                for (var k = 0; k < order.Length; k++)
                {
                    var question = questions[k];
                    switch (question.QuestionType)
                    {
                    case "SingleChoiceQuestion":
                        answer = new SingleChoiceAnswer();
                        break;

                    case "MultiChoiceQuestion":
                        answer = new MultiChoiceAnswer();
                        break;

                    case "TextQuestion":
                        answer = new TextAnswer();
                        break;

                    case "DragAndDropQuestion":
                        answer = new DragAndDropAnswer();
                        break;

                    case "CodeQuestion":
                        answer = new CodeAnswer();
                        break;
                    }

                    if (answer == null)
                    {
                        throw new NullReferenceException();
                    }
                    answer.Result     = null;
                    answer.Question   = question;
                    answer.Score      = 0;
                    answer.TestResult = testResult;
                    answer.Order      = order[j++];
                    _context.Answers.Add(answer);
                    answers.Add(answer);
                    _context.SaveChanges();
                }
            }
            else
            {
                var order = new ushort[questions.Count()];
                for (var i = 0; i < order.Length; i++)
                {
                    order[i] = (ushort)(i + 1);
                }

                var j = 0;
                foreach (var question in questions)
                {
                    switch (question.QuestionType)
                    {
                    case "SingleChoiceQuestion":
                        answer = new SingleChoiceAnswer();
                        break;

                    case "MultiChoiceQuestion":
                        answer = new MultiChoiceAnswer();
                        break;

                    case "TextQuestion":
                        answer = new TextAnswer();
                        break;

                    case "DragAndDropQuestion":
                        answer = new DragAndDropAnswer();
                        break;

                    case "CodeQuestion":
                        answer = new CodeAnswer();
                        break;
                    }

                    if (answer == null)
                    {
                        throw new NullReferenceException();
                    }
                    answer.Question   = question;
                    answer.Score      = 0;
                    answer.TestResult = testResult;
                    answer.Order      = order[j++];
                    _context.Answers.Add(answer);
                    answers.Add(answer);
                    _context.SaveChanges();
                }
            }

            testResult.StartedOn = DateTime.UtcNow;
            _context.TestResults.Update(testResult);
            _context.SaveChanges();
        }