public async Task CreateAsync(
            int pollId,
            string title,
            IEnumerable <string> answerOptions)
        {
            var question = new Question
            {
                Title  = title,
                PollId = pollId
            };

            await this.db.AddAsync(question);

            var allAnswerOptions = new List <AnswerOption>();

            foreach (var answerOption in answerOptions)
            {
                var answerOptionDb = new AnswerOption
                {
                    QuestionId = question.Id,
                    Text       = answerOption
                };

                await this.db.AddAsync(answerOptionDb);

                allAnswerOptions.Add(answerOptionDb);
            }

            await this.db.SaveChangesAsync();
        }
示例#2
0
 public void CreateAnswerOption(AnswerOption answer)
 {
     using (var ctx = _dataContextFactory.Create()) {
         ctx.InsertOnSubmit(answer);
         ctx.SubmitChanges();
     }
 }
        public JsonResult Submit(List <ObjectiveTest> answers)
        {
            int    answeredTime    = 0;
            int?   score           = 0;
            string explanation     = "";
            bool   failedImportant = false;

            foreach (var answer in answers)
            {
                answeredTime = answer.TimeTaken;

                if (answer.CorrectAnswerID == answer.Answered)
                {
                    decimal?responsePercentage  = ERDal.ResponsePercentage(answer.AllowedTime, answeredTime);
                    int?    scoreByResponseTime = ERDal.CalculateScoreByResponseTime(responsePercentage, answer.Score);
                    score = score + scoreByResponseTime;
                }
                else
                {
                    if (answer.Priority == "Important")
                    {
                        failedImportant = true;
                        string       CandidateAnswer = "";
                        AnswerOption ansOp           = new AnswerOption();
                        if (answer.Answered != null)
                        {
                            ansOp = TD.AnswerOptions.Find(answer.Answered == null ? 0 : answer.Answered);

                            CandidateAnswer = ". <br /> You have answered " + ansOp.AnswerOptionsDescription;
                        }


                        ansOp = TD.AnswerOptions.Find(answer.CorrectAnswerID);
                        string correctAnswer = ansOp.AnswerOptionsDescription;
                        explanation = explanation + "You have failed to answer an important question " + answer.Question + CandidateAnswer + ". <br /> The correct answer is " + correctAnswer + ". <br /> Unfortunately this time you lost your score as you have to ..... ";
                    }
                    score = score - 1;
                }
            }
            // Session["CandidateId"] = 4;
            if (failedImportant == true)
            {
                score = 0;
            }
            int Grade       = ERDal.CalculateGrade(score);
            int CandidateId = Convert.ToInt32(Session["CandidateId"]);

            int        ExamId = ERDal.ExamTypeId("Objective");
            ExamResult ER     = new ExamResult();

            ER.CandidateId = CandidateId;
            ER.ExamId      = ExamId;
            ER.Date        = DateTime.Now.ToString("dd/MM/yyyy");
            ER.Score       = score;
            ER.Grade       = Grade;
            ER.Explanation = explanation;
            int examResults = ERDal.SaveScore(ER);

            return(Json("OK", JsonRequestBehavior.AllowGet));
        }
示例#4
0
        private void Bind()
        {
            if (!Id.Equals(Guid.Empty))
            {
                Page.Title = "编辑答案想选";

                AnswerOption bll   = new AnswerOption();
                var          model = bll.GetModel(Id);
                if (model != null)
                {
                    txtName.Value      = model.OptionContent;
                    qsId.Value         = model.QuestionSubjectId.ToString();
                    selectIsTrue.Value = model.IsTrue.ToString();
                    sort.Value         = model.Sort.ToString();
                    hId.Value          = Id.ToString();
                    if (model.IsDisable)
                    {
                        rdFalse.Checked = false;
                        rdTrue.Checked  = true;
                    }
                    else
                    {
                        rdFalse.Checked = true;
                        rdTrue.Checked  = false;
                    }
                }
            }
            else
            {
                qsId.Value = Request["qsId"];
            }
        }
示例#5
0
        public static void AnswerInsert(AnswerOption option, string userID)
        {
            var paramList = new List <ParameterValue>();

            if (!string.IsNullOrEmpty(userID))
            {
                paramList.Add(new ParameterValue("UserID", userID));
            }

            if (!string.IsNullOrEmpty(option.IDQuestionOption))
            {
                paramList.Add(new ParameterValue("idQuestionOption", option.IDQuestionOption));
            }
            if (!string.IsNullOrEmpty(option.IDQuestion))
            {
                paramList.Add(new ParameterValue("idQuestion", option.IDQuestion));
            }
            if (!string.IsNullOrEmpty(option.IDQuestionnaire))
            {
                paramList.Add(new ParameterValue("idQuestionnaire", option.IDQuestionnaire));
            }
            if (!string.IsNullOrEmpty(option.ColumnNo))
            {
                paramList.Add(new ParameterValue("ColumnNo", option.ColumnNo));
            }
            if (!string.IsNullOrEmpty(option.Answer))
            {
                paramList.Add(new ParameterValue("Answer", option.Answer));
            }


            DataFacade.ExecuteNonQuery("AnswerInsert", paramList.ToArray());
        }
示例#6
0
        public static AnswerOption FindTemplateQuestion(string id)
        {
            var r = DataFacade.GetDataRow("TemplateQuestionGet",
                                          new[] { new ParameterValue("idTemplateQuestion", id) });

            if (r == null)
            {
                return(new AnswerOption());
            }

            var l = new AnswerOption
            {
                IDTemplateQuestionnaire = r["idTemplateQuestionnaire"].ToString(),
                IDTemplateQuestion      = r["idTemplateQuestion"].ToString(),
                IDAnswerType            = r["idAnswerType"].ToString(),
                Section           = r["Section"].ToString(),
                Question          = r["Question"].ToString(),
                ColumnSelf        = r["ColumnSelf"].ToString(),
                ColumnPartner     = r["ColumnPartner"].ToString(),
                ColumnCustom      = r["ColumnCustom"].ToString(),
                Mandatory         = r["Mandatory"].ToString(),
                ShowOptionNumbers = r["ShowOptionNumbers"].ToString(),
            };

            return(l);
        }
        public void FillData()
        {
            answerOptionArray = answerOptionService.GetAll();
            ListBox.ItemsSource = answerOptionArray;

            AnswerOption qwe = new AnswerOption();
        }
        public async Task DeleteAsyncShouldDeleteAnswer()
        {
            // Arrange
            var db = Tests.GetDatabase();

            var answer1 = new AnswerOption {
                Id = 1
            };
            var answer2 = new AnswerOption {
                Id = 2
            };
            var answer3 = new AnswerOption {
                Id = 3
            };

            await db.AddRangeAsync(answer1, answer2, answer3);

            await db.SaveChangesAsync();

            var answerService = new AnswerService(db);

            // Act
            await answerService.DeleteAsync(2);

            var result = await db.AnswerOptions.ToListAsync();

            // Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == 1 &&
                   r.ElementAt(1).Id == 3)
            .And
            .HaveCount(2);
        }
示例#9
0
        public AnswerOption CreateNewAnswerOption(AnswerOption NewAnswerOption)
        {
            try
            {
                if (_conn.State == System.Data.ConnectionState.Closed)
                {
                    _conn.Open();
                }
                // For MVP new question IsActive will be default posted as true, after MVP development will accommodate for Admin to select active questions from a list of all questions in DB
                MySqlCommand cmd = new MySqlCommand($"INSERT INTO Question_AnswerOptions (Questions_Questions_Id, AnswerOption_IsCorrectOption, AnswerOption_Option) " +
                                                    $"VALUES (@Questions_Questions_Id, @AnswerOption_IsCorrectOption, @AnswerOption_Option)", _conn);

                using (cmd)
                {
                    cmd.Parameters.AddWithValue("@Questions_Questions_Id", $"{NewAnswerOption.QuestionId}");
                    cmd.Parameters.AddWithValue("@AnswerOption_IsCorrectOption", $"{Convert.ToInt32(NewAnswerOption.IsCorrectOption)}");
                    cmd.Parameters.AddWithValue("@AnswerOption_Option", $"{NewAnswerOption.Option}");
                    cmd.ExecuteNonQuery();
                }
                _conn.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            return(GetAnswerOptionDataByAnswerOption(NewAnswerOption));
        }
        public async Task <IActionResult> AddAnswerOption(int id)
        {
            //Retrieve Question
            var questions = await _context.Question
                            .Where(question => question.QuestionId == id)
                            .Include(question => question.AnswerOptions)
                            .ToListAsync();

            var selectedQuestion = questions.FirstOrDefault();

            /*Check if it already has the max number of answers, add error to TempData if so.
             * Edit action checks for temp data and adds validation errors if populated*/
            if (selectedQuestion.AnswerOptions.Count >= 5)
            {
                TempData["CannotAddAnswers"] = true;
                TempData.Save();
                return(RedirectToAction("Edit", new { id = id, Question = selectedQuestion }));
            }

            //Create new blank answer
            var newAnswer = new AnswerOption()
            {
                AnswerText = "",
                QuestionId = id
            };

            //Add to question and save in DB
            selectedQuestion.AnswerOptions.Add(newAnswer);
            _context.Question.Update(selectedQuestion);
            await _context.SaveChangesAsync();

            //Reload the edit question view
            return(RedirectToAction("Edit", new { id = id }));
        }
示例#11
0
        public bool Post([FromBody] AnswerOption Option)
        {
            AnswerOption _newAnswerOption = _answerOptionService.CreateNewAnswerOption(Option);
            bool         _isNewAnswerOptionCreationSuccessful = _answerOptionService.IsNewAnswerOptionCreationSuccessful(_newAnswerOption.Id);

            return(_isNewAnswerOptionCreationSuccessful);
        }
示例#12
0
        private static async Task SeedTestDatabaseAnswers(ApplicationDbContext dbContext, List <Question> questions)
        {
            var answerOptions = new List <AnswerOption>();

            var answerIdCounter = 1;

            foreach (var question in questions)
            {
                for (var index = 1; index <= AnswersPerQuestion; index++)
                {
                    var answerOption = new AnswerOption {
                        AnswerOptionId = answerIdCounter
                    };

                    answerOption.AnswerText = $"Text of Answer {answerOption.AnswerOptionId}";
                    answerOption.Correct    = index % AnswersPerQuestion == 0;
                    answerOption.QuestionId = question.QuestionId;

                    answerOptions.Add(answerOption);

                    answerIdCounter += 1;
                }
            }

            await dbContext.AnswerOption.AddRangeAsync(answerOptions);

            await dbContext.SaveChangesAsync();
        }
        public async Task AnswerExistAsyncShouldReturnTrueIfAnswerExist()
        {
            // Arrange
            var db = Tests.GetDatabase();

            var answer1 = new AnswerOption {
                Id = 1
            };
            var answer2 = new AnswerOption {
                Id = 2
            };
            var answer3 = new AnswerOption {
                Id = 3
            };

            await db.AddRangeAsync(answer1, answer2, answer3);

            await db.SaveChangesAsync();

            var answerService = new AnswerService(db);

            // Act
            var result = await answerService.AnswerExistAsync(1);

            // Assert
            result
            .ShouldBeEquivalentTo(true);
        }
示例#14
0
        public async Task EditAsync(int questionId, string title, IEnumerable <string> answerOptions, IEnumerable <int> answerOptionsIds)
        {
            var question = await this.db.Questions.FindAsync(questionId);

            question.Title = title;

            var answers = new List <string>(answerOptions);

            foreach (var answerId in answerOptionsIds)
            {
                var answer = await this.db.AnswerOptions.FindAsync(answerId);

                foreach (var answerText in answers.ToList())
                {
                    answer.Text = answerText;
                    answers.Remove(answerText);
                    break;
                }
                await this.db.SaveChangesAsync();
            }
            foreach (var answer in answers)
            {
                var answerOptionDb = new AnswerOption
                {
                    QuestionId = questionId,
                    Text       = answer
                };

                await this.db.AddAsync(answerOptionDb);
            }

            await this.db.SaveChangesAsync();
        }
示例#15
0
        public void Delete(AnswerOption o)
        {
            using (var db = new LiteDatabase(Constants.DB_NAME))
            {
                var answerOptions = db.GetCollection <AnswerOption>("AnswerOption");

                answerOptions.Delete(o.Id);
                answerOptions.EnsureIndex("Id");
            }
        }
        //
        // GET: /AnswerOption/Edit/5
        /// <summary>
        /// Edit view
        /// </summary>
        /// <param name="id">question id</param>
        /// <param name="number">answer option number</param>
        /// <returns>CreateEdit</returns>
        public ActionResult Edit(int id = 0, int number = 0)
        {
            AnswerOption answeroption = db.AnswerOptions.Find(id, number);

            if (answeroption == null)
            {
                return(HttpNotFound());
            }

            return(View("CreateEdit", answeroption));
        }
示例#17
0
        public void UpdateAnswerOption(AnswerOption answersOption)
        {
            AnswerOption existing = GetAnswerOptionsByQuestionId(answersOption.QuestionId);

            existing.CorrectAnswer = answersOption.CorrectAnswer;
            existing.CorrectOption = answersOption.CorrectOption;
            existing.Opt1          = answersOption.Opt1;
            existing.Opt2          = answersOption.Opt2;
            existing.Opt3          = answersOption.Opt3;
            existing.Opt4          = answersOption.Opt4;
            db.SaveChanges();
        }
        public AnswerOption MapAnswersToQuestion(int QuestionId, AnswerWithIsCorrect Answer)
        {
            AnswerOption _answer = new AnswerOption();

            _answer.QuestionId      = QuestionId;
            _answer.Option          = Answer.Answer;
            _answer.IsCorrectOption = Answer.IsCorrect;

            _answer = _answerOptionService.CreateNewAnswerOption(_answer);

            return(_answer);
        }
示例#19
0
        public Answer GetOrCreateAnswer(Exam exam, Question question)
        {
            if (exam == null)
            {
                throw new ArgumentNullException(nameof(exam));
            }
            if (!exam.ExamID.HasValue)
            {
                throw new ArgumentException("The exam must be saved before answers can be created");
            }

            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (!question.QuestionID.HasValue)
            {
                throw new ArgumentException("The question must be saved before answers can be created");
            }

            using (var cmd = _sessionManager.GetCurrentUnitOfWork().CreateSPCommand("QA_GetOrCreateAnswer"))
            {
                using (var dr = cmd.CreateAndAddParameter("ExamID", DbType.Int32, exam.ExamID.Value)
                                .CreateAndAddParameter("QuestionID", DbType.Int32, question.QuestionID.Value)
                                .ExecuteReader())
                {
                    var answer = new Answer();
                    if (dr.Read())
                    {
                        answer.QuestionID = dr.GetInt32("QuestionID");
                        answer.AnswerID   = dr.GetInt32("AnswerID");
                        answer.ExamID     = dr.GetInt32("ExamID");
                    }
                    else
                    {
                        throw new DataException("No rows were returned by QA_GetOrCreateAnswer");
                    }

                    var options = new List <AnswerOption>();
                    dr.NextResult();
                    while (dr.Read())
                    {
                        var ao = new AnswerOption();
                        ao.QuestionID = answer.QuestionID;
                        ao.AnswerID   = answer.AnswerID.Value;
                        ao.OptionID   = dr.GetInt32("OptionID");
                    }
                    answer.AnswerOptions = options;

                    return(answer);
                }
            }
        }
 protected void rptOptions_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.DataItem is Question)
     {
         Question     question = (Question)e.Item.DataItem;
         AnswerOption op       = _currentGroup.AnswerSheet.GetOption(question);
         if (op.Option > 0)
         {
             ValueBinder.BindLiteral(e.Item, "litOption", _currentGroup.Group.Selections[op.Option - 1]);
         }
     }
 }
示例#21
0
        public void SetMcqAnswers(string correctAnswer, List <string> options, Guid trackingGuid = default(Guid))
        {
            if (string.IsNullOrEmpty(correctAnswer) || string.IsNullOrWhiteSpace(correctAnswer))
            {
                throw new DomainValidationException(trackingGuid, "Correct Answer Cannot be empty", 8);
            }

            if (options == null || !options.Any())
            {
                throw new DomainValidationException(trackingGuid, "No option present", 6);
            }

            _answerOptions = AnswerOption.CreateOptions(correctAnswer, options);
            _answer        = new Answer(_answerOptions.First(option => option.IsCorrect));
        }
        //
        // GET: /AnswerOption/Create
        /// <summary>
        /// returns create view
        /// </summary>
        /// <param name="id">question id</param>
        /// <returns>CreateEdit</returns>
        public ActionResult Create(int id = 0)
        {
            Question parentQuestion = db.Questions.Find(id);

            if (parentQuestion == null)
            {
                return(HttpNotFound());
            }

            AnswerOption answeroption = new AnswerOption {
                questionId = id, Question = parentQuestion
            };

            return(View("CreateEdit", answeroption));
        }
示例#23
0
        public JsonResult AddQuestion(AnswerOption newQuestion)
        {
            AnswerOption question = new AnswerOption()
            {
                Question      = newQuestion.Question,
                Option1       = newQuestion.Option1,
                Option2       = newQuestion.Option2,
                Option3       = newQuestion.Option3,
                CorrectAnswer = newQuestion.CorrectAnswer
            };

            _context.AnswerOptions.Add(question);
            _context.SaveChanges();

            return(Json(newQuestion));
        }
        //
        // GET: /AnswerOption/Delete/5
        /// <summary>
        /// Goes to Delete view
        /// </summary>
        /// <param name="id">question id</param>
        /// <param name="number">answer number</param>
        /// <returns>Delete view</returns>
        public ActionResult Delete(int id = 0, int number = 0)
        {
            AnswerOption answeroption = db.AnswerOptions.Find(id, number);

            if (answeroption == null)
            {
                return(HttpNotFound());
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(answeroption));
            }

            return(View(answeroption));
        }
示例#25
0
        private void Bind()
        {
            int totalRecords = 0;

            if (!string.IsNullOrEmpty(qsId.Value))
            {
                //查询条件
                GetSearchItem();

                AnswerOption bll = new AnswerOption();

                rpData.DataSource = bll.GetListOW(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                rpData.DataBind();
            }

            myDataAppend.Append("<div id=\"myDataForPage\" style=\"display:none;\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>");
        }
        public void SubmitQuestionnaire()
        {
            using (var client = new QuestionnaireClient())
            {
                var model = new SubmitQuestionnaireRequest();
                model.PageID          = new Guid("803BCF2F-6433-4AE9-B023-4BB730FFA5FE");
                model.QuestionnaireID = 1;

                //问题1
                var question1 = new Question();
                question1.QuestionID = 1;
                var questionOption1 = new AnswerOption();
                questionOption1.AnswerOptionID = 1;
                question1.AnswerOptionList     = new List <AnswerOption>();
                question1.AnswerOptionList.Add(questionOption1);

                //问题2
                var question3 = new Question();
                question3.QuestionID = 4;
                var questionOption3 = new AnswerOption();
                questionOption3.AnswerOptionID = 11;
                var questionOption3A = new AnswerOption();
                questionOption3A.AnswerOptionID = 13;
                question3.AnswerOptionList      = new List <AnswerOption>();
                question3.AnswerOptionList.Add(questionOption3);
                question3.AnswerOptionList.Add(questionOption3A);

                //问题3
                var question2 = new Question();
                question2.QuestionID = 8;
                var questionOption2 = new AnswerOption();
                questionOption2.AnswerOptionID = 24;
                questionOption2.AnswerText     = "服务很好,很满意!";
                question2.AnswerOptionList     = new List <AnswerOption>();
                question2.AnswerOptionList.Add(questionOption2);

                model.QuestionList = new List <Question>();
                model.QuestionList.Add(question1);
                model.QuestionList.Add(question2);
                model.QuestionList.Add(question3);

                var result = client.SubmitQuestionnaire(model);
                Assert.IsNotNull(result.Result);
            }
        }
示例#27
0
        private static void Continue()
        {
            Console.WriteLine("Continue: Y | N");
            AnswerOption answer = EnumMapper.ReadContinueOption(Console.ReadLine().ToLower().Trim());

            switch (answer)
            {
            case AnswerOption.n:
            case AnswerOption.unknown:
                break;

            case AnswerOption.y:
            default:
                Console.Clear();
                Main();
                break;
            }
        }
示例#28
0
        public List <AnswerOption> GetAllAnswerOptionsForQuestion(int QuestionId)
        {
            List <AnswerOption> list = new List <AnswerOption>();

            try
            {
                if (_conn.State == System.Data.ConnectionState.Closed)
                {
                    _conn.Open();
                }
                MySqlCommand cmd = new MySqlCommand($"SELECT * FROM Question_AnswerOptions WHERE Questions_Questions_Id = {QuestionId}", _conn);

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            AnswerOption _answerOption = new AnswerOption
                            {
                                Id              = Convert.ToInt32(reader["AnswerOption_Id"]),
                                QuestionId      = Convert.ToInt32(reader["Questions_Questions_Id"]),
                                IsCorrectOption = reader.GetBoolean("AnswerOption_IsCorrectOption"),
                                Option          = reader["AnswerOption_Option"].ToString(),
                                Created         = reader["AnswerOptions_Created"].ToString(),
                                Modified        = reader["AnswerOptions_Modified"].ToString()
                            };

                            list.Add(_answerOption);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                _conn.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            return(list);
        }
        public ActionResult DeleteConfirmed(int id = 0, int number = 0)
        {
            AnswerOption answeroption      = db.AnswerOptions.Find(id, number);
            bool         hasCustomerAnswer = db.CustomerAnswers.Any(x => x.questionId == id &&
                                                                    x.answerOptionNumber == number);

            if (!hasCustomerAnswer)
            {
                db.AnswerOptions.Remove(answeroption);
                db.SaveChanges();
            }
            else
            {
                TempData["Message"] = String.Format("Cannot delete because the answer option '{0}' was used as customer answer",
                                                    answeroption.answerText);
            }

            return(RedirectToAction("Details", "Question", new { id = id }));
        }
示例#30
0
        public AnswerOption GetAnswerOptionDataByAnswerOption(AnswerOption NewAnswerOption)
        {
            try
            {
                if (_conn.State == System.Data.ConnectionState.Closed)
                {
                    _conn.Open();
                }
                // Must find a way to allow quote and apostraphes in questions without SQL error
                // To get this method to succeed, the front end application will search string and apply a \ before posting.
                MySqlCommand cmd = new MySqlCommand($"SELECT * FROM Question_AnswerOptions WHERE AnswerOption_Option = \"{NewAnswerOption.Option}\"", _conn);

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            return(new AnswerOption()
                            {
                                Id = Convert.ToInt32(reader["AnswerOption_Id"]),
                                QuestionId = Convert.ToInt32(reader["Questions_Questions_Id"]),
                                IsCorrectOption = reader.GetBoolean("AnswerOption_IsCorrectOption"),
                                Option = reader["AnswerOption_Option"].ToString(),
                                Created = reader["AnswerOptions_Created"].ToString(),
                                Modified = reader["AnswerOptions_Modified"].ToString()
                            });
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                _conn.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            return(null);
        }
示例#31
0
        public int SeedAnswerOption(int recs, AnswerGroup _answerGroup)
        {
            // default: create 5 options for a group
            for (int i = 1; i <= recs; i++)
            {
                var row = new AnswerOption
                {
                    AnswerVal   = i,
                    AnswerGroup = _answerGroup,
                    AnswerText  = "Group " + Convert.ToString(_answerGroup.Id) + " Choice " + Convert.ToString(i)
                };

                _answerOption.Add(row);
            }

            //verify result
            int count = _answerOption.GetAll().Count();

            return(count);
        }