public ExamAnswer GetExamAnswer(RequestGetExamAnswer request)
        {
            ExamAnswerHelper eah = new ExamAnswerHelper();
            ExamAnswer       ea  = eah.GetRow(request.usercode, request.ExamPaper);

            AnswerHelper ah = new AnswerHelper();

            ea.Answers = ah.GetRows(ea.GUID);

            AnswerItemHelper aih = new AnswerItemHelper();
            var ais = aih.GetRows(ea.GUID);

            Dictionary <string, IList <AnswerItem> > items = new Dictionary <string, IList <AnswerItem> >();

            foreach (var ai in ais)
            {
                if (!items.ContainsKey(ai.Code))
                {
                    items.Add(ai.Code, new List <AnswerItem>());
                }
                items[ai.Code].Add(ai);
            }

            foreach (var a in ea.Answers)
            {
                a.Answers = items[a.Code];
            }

            return(ea);
        }
Пример #2
0
        public void TestExamResult()
        {
            int userId = 1;

            QuestionAnswer answer1  = new QuestionAnswer("Ostrava", true);
            QuestionAnswer answer2  = new QuestionAnswer("Praha", false);
            Question       question = QuestionTable.InsertQuestion(this.connection, userId, "test", "closed", new List <QuestionAnswer>()
            {
                answer1, answer2
            });

            Exam exam = ExamTable.InsertExam(this.connection, userId, "test exam", 10, 1, 1, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1));

            exam.AddQuestion(question.Id, 20);
            ExamTable.UpdateExam(this.connection, exam);

            int        examResultId = ExamResultTable.InsertExamResult(this.connection, exam.Id, userId);
            ExamResult examResult   = ExamResultTable.GetExamResultById(this.connection, examResultId);

            Assert.AreEqual(examResultId, examResult.Id);
            Assert.AreEqual(userId, examResult.OwnerId);
            Assert.AreEqual("created", examResult.State);

            ExamAnswer answer = new ExamAnswer(question.Id, "Ostrava");

            Assert.IsTrue(ExamResultTable.HandInExamResult(this.connection, examResult, new List <ExamAnswer>()
            {
                answer
            }));

            examResult = ExamResultTable.GetExamResultById(this.connection, examResult.Id);

            Assert.AreEqual("finished", examResult.State);
            Assert.AreEqual(exam.Questions[0].Points, examResult.Points);
        }
Пример #3
0
 public TestResult AddTestResult(ExamAnswer examAnswer)
 {
     var context = new SchoolContext();
     var testResult = new TestResult();
     context.TestResults.Add(testResult);
     context.SaveChanges();
     return testResult;
 }
Пример #4
0
        private static Mock <IExamAnswerManager> CreateExamManagerMock(ExamAnswer answer)
        {
            var examManagerMock = new Mock <IExamAnswerManager>();

            examManagerMock.Setup(m =>
                                  m.GetAnswer(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(answer);
            return(examManagerMock);
        }
Пример #5
0
        public void TestExamGraderOneCorrectOneIncorrectAnswer()
        {
            ExamAnswer answer            = CreateExameAnswer(1, 1);
            var        testResultManager = GradeExam(answer);

            testResultManager.Verify(c =>
                                     c.SetTotalScore(It.IsAny <DataInterface.TestResult>(), It.Is <decimal>(m => m == 0.5m)),
                                     Times.Once());
        }
Пример #6
0
        private static Mock <ITestResultManager> GradeExam(ExamAnswer answer)
        {
            var examManagerMock   = CreateExamManagerMock(answer);
            var testResultManager = CreateTestResultManagerMock();

            var examGrader = new ExamGrader(testResultManager.Object, examManagerMock.Object);

            examGrader.GradeExam("A", "B", 0);
            return(testResultManager);
        }
Пример #7
0
        public void AddExamQuestionAnswer(ExamAnswer examAnswer, Question question, AnswerAlternative option)
        {
            var context            = new SchoolContext();
            var examQuestionAnswer = new ExamQuestionAnswer();

            examQuestionAnswer.AnswerAlternativeID = option.AnswerAlternativeID;
            examQuestionAnswer.ExamAnswerID        = examAnswer.ExamAnswerID;
            examQuestionAnswer.QuestionID          = question.QuestionID;
            context.ExamQuestionAnswers.Add(examQuestionAnswer);
            context.SaveChanges();
        }
Пример #8
0
        public ExamAnswer AddExamAnswer(string studentName, Exam exam)
        {
            var context    = new SchoolContext();
            var examAnswer = new ExamAnswer();

            examAnswer.StudentID = (new StudentManager()).GetStudentByName(studentName).StudentID;
            examAnswer.ExamID    = exam.ExamID;
            context.ExamAnswers.Add(examAnswer);
            context.SaveChanges();
            return(examAnswer);
        }
Пример #9
0
        private ExamAnswer CreateExameAnswer(int correct, int incorrect)
        {
            var answer = new ExamAnswer();

            answer.Exam                = new Exam();
            answer.Exam.Questions      = new List <Question>();
            answer.ExamQuestionAnswers = new List <ExamQuestionAnswer>();
            for (int i = 0; i < correct + incorrect; i++)
            {
                CreateOneQuestionAnswerPair(correct, answer, i);
            }
            return(answer);
        }
Пример #10
0
        private void CreateOneQuestionAnswerPair(int numberOfCorrectAnswer, ExamAnswer answer, int currentAnswerIndex)
        {
            int studentAnswerId = AnswerAlternativeId;
            List <AnswerAlternative> answerAlternatives = CreateAnswerAlternatives(numberOfCorrectAnswer, currentAnswerIndex);

            answer.ExamQuestionAnswers.Add(
                new ExamQuestionAnswer {
                QuestionID = currentAnswerIndex, AnswerAlternativeID = studentAnswerId
            });
            answer.Exam.Questions.Add(
                new Question {
                AnswerAlternatives = answerAlternatives, QuestionID = currentAnswerIndex
            });
        }
Пример #11
0
 public void SaveAnswer(ExamAnswer ea)
 {
     if (ea.Id == 0)
     {
         _db.ExamAnswers.Add(ea);
     }
     else
     {
         var entity = _db.ExamAnswers.Find(ea.Id);
         if (entity != null)
         {
             entity.ExamQuestion = ea.ExamQuestion;
             entity.ExamOption   = ea.ExamOption;
         }
         _db.Entry(entity).State = EntityState.Modified;
     }
     _db.SaveChanges();
 }
        public ResultMessage SetExamAnswer(ExamAnswer request)
        {
            ExamAnswerHelper eah    = new ExamAnswerHelper();
            ResultMessage    result = eah.Create(request.GUID = Guid.NewGuid().ToString(), request.ExamPaper, request.UserCode, request.ClientIP, request.LeftTime, request.RightTime, request.TotalScore);

            if (!result.State)
            {
                return(result);
            }

            AnswerHelper     ah  = new AnswerHelper();
            AnswerItemHelper aih = new AnswerItemHelper();

            if (request.Answers == null || request.Answers.Count == 0)
            {
                return(result);
            }
            foreach (var a in request.Answers)
            {
                result = ah.Create(a.GUID = Guid.NewGuid().ToString(), a.Ref_ExamAnswer_GUID = request.GUID, a.Code, a.Score, a.Comment);
                if (!result.State)
                {
                    return(result);
                }

                if (a.Answers == null || a.Answers.Count == 0)
                {
                    continue;
                }
                foreach (var ai in a.Answers)
                {
                    if (string.IsNullOrWhiteSpace(ai.ItemOrder))
                    {
                        continue;
                    }
                    result = aih.Create(ai.GUID = Guid.NewGuid().ToString(), ai.Answer_GUID = a.GUID, ai.ItemOrder, ai.Value, ai.ExpandValue);
                    if (!result.State)
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
Пример #13
0
        public static IList <ExamAnswer> GetExamAnswerListByQuestonId(int questionId)
        {
            IList <ExamAnswer> examAnswerList = new List <ExamAnswer>();
            ExamAnswer         examAnswer     = null;
            string             strSql         = "SELECT AnswerId,QuestionId,AnswerName FROM ExamAnswer WHERE QuestionID = @QuestionId ORDER BY AnswerID ASC";
            SqlParameter       parm           = new SqlParameter("@QuestionID", questionId);

            using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, parm)){
                while (dr.Read())
                {
                    examAnswer            = new ExamAnswer();
                    examAnswer.AnswerID   = Convert.ToInt32(dr["AnswerId"]);
                    examAnswer.AnswerName = dr["AnswerName"].ToString();
                    examAnswer.QuestionID = questionId;

                    examAnswerList.Add(examAnswer);
                }
            }

            return(examAnswerList);
        }
Пример #14
0
        public void GradeExam(ExamAnswer examAnswer)
        {
            ITestResultManager testResultManager = new TestResultManager();
            var testResult = testResultManager.AddTestResult(examAnswer);
            int correct    = 0;
            int total      = 0;

            foreach (var question in examAnswer.Exam.Questions)
            {
                var studentAnswer = examAnswer.ExamQuestionAnswers.FirstOrDefault(eqa =>
                                                                                  eqa.QuestionID == question.QuestionID);
                var isCorrect = studentAnswer.AnswerAlternativeID ==
                                question.AnswerAlternatives.FirstOrDefault(a => a.IsCorrect)?.AnswerAlternativeID;
                testResultManager.AddAnswer(testResult, studentAnswer.AnswerAlternative, isCorrect);
                if (isCorrect)
                {
                    correct++;
                }
                total++;
            }
            testResultManager.SetTotalScore(testResult, (decimal)correct / (decimal)total);
        }
Пример #15
0
 private static void GenerateAnswers(int i, int correct, ExamQuestion question, List <ExamAnswer> answers)
 {
     if (i == correct)
     {
         var answer = new ExamAnswer()
         {
             QuestionId    = question.QuestionId,
             AnswerContent = $"ANSWER{i}",
             Correct       = 1
         };
         answers.Add(answer);
     }
     else
     {
         var answer = new ExamAnswer()
         {
             QuestionId    = question.QuestionId,
             AnswerContent = $"ANSWER{i}",
             Correct       = 0
         };
         answers.Add(answer);
     }
 }
Пример #16
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(ExamAnswer model)
 {
     this._repoExamAnswer.Delete(model);
 }
Пример #17
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ExamAnswer Insert(ExamAnswer model)
 {
     return(this._repoExamAnswer.Insert(model));
 }
Пример #18
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(ExamAnswer model)
 {
     this._repoExamAnswer.Update(model);
 }
Пример #19
0
        public ActionResult AddQuestion(SingleQuestionUpload squ, HttpPostedFileBase upload)
        {
            int ex = squ.ExamId;

            if (ModelState.IsValid)
            {
                var kdk = new ExamQuestion
                {
                    Examination     = _examinationRepository.GetExaminationData(squ.ExamId),
                    QuestionContent = squ.Question
                };

                var quest = _examinationRepository.SaveQuestion(kdk, upload);
                //add options
                var eo1 = new ExamOption
                {
                    OptionContent = squ.Option1,
                    ExamQuestion  = quest
                };
                var op1 = _examinationRepository.SavExamOption(eo1);

                var eo2 = new ExamOption
                {
                    OptionContent = squ.Option2,
                    ExamQuestion  = quest
                };
                var op2 = _examinationRepository.SavExamOption(eo2);

                var eo3 = new ExamOption
                {
                    OptionContent = squ.Option3,
                    ExamQuestion  = quest
                };
                var op3 = _examinationRepository.SavExamOption(eo3);

                var eo4 = new ExamOption
                {
                    OptionContent = squ.Option4,
                    ExamQuestion  = quest
                };
                var op4 = _examinationRepository.SavExamOption(eo4);

                var eo5 = new ExamOption
                {
                    OptionContent = squ.Option5,
                    ExamQuestion  = quest
                };
                var op5 = _examinationRepository.SavExamOption(eo5);


                int value = squ.AnswerIdentifier;
                //save answer
                switch (value)
                {
                case 1:
                    var ans1 = new ExamAnswer
                    {
                        ExamQuestion = quest,
                        ExamOption   = op1
                    };
                    _examinationRepository.SaveAnswer(ans1);
                    break;


                case 2:
                    var ans2 = new ExamAnswer
                    {
                        ExamQuestion = quest,
                        ExamOption   = op2
                    };
                    _examinationRepository.SaveAnswer(ans2);
                    break;

                case 3:
                    var ans3 = new ExamAnswer
                    {
                        ExamQuestion = quest,
                        ExamOption   = op3
                    };
                    _examinationRepository.SaveAnswer(ans3);
                    break;

                case 4:
                    var ans4 = new ExamAnswer
                    {
                        ExamQuestion = quest,
                        ExamOption   = op4
                    };
                    _examinationRepository.SaveAnswer(ans4);
                    break;

                case 5:
                    var ans5 = new ExamAnswer
                    {
                        ExamQuestion = quest,
                        ExamOption   = op5
                    };
                    _examinationRepository.SaveAnswer(ans5);
                    break;
                }
            }
            TempData["notification"] = "The Question has been successfully uploaded";
            return(RedirectToAction("Qustion", new { examId = ex }));
        }
Пример #20
0
        public async Task <IActionResult> WriteAnswer(WriteAnswersDto writeAnswersDto)
        {
            //Вземане на studentId и testId от header - exam
            ExamDto examDto = JsonConvert.DeserializeObject <ExamDto>(Request.Headers["Exam"]);

            if (examDto.TestId == 0 || examDto.StudentId == 0 || String.IsNullOrEmpty(examDto.Token))
            {
                return(NotFound());
            }

            var student = await _context.Students
                          .Include(stt => stt.StudentToTest)
                          .FirstOrDefaultAsync(s => s.Id == examDto.StudentId &&
                                               s.StudentToTest.TestId == examDto.TestId &&
                                               s.StudentToTest.Id == examDto.Token);

            if (student == null)
            {
                return(Unauthorized());
            }

            var question = await _context.TestQuestions
                           .Include(tqa => tqa.TestQuestionAnswers)
                           .Include(tqt => tqt.TestQuestionType)
                           .FirstOrDefaultAsync(tq => tq.Id == writeAnswersDto.Id);

            int studentAnswers = writeAnswersDto.Answers.Count();

            //Проверява дали броят на отговорите не превишата с този на типът тест
            if (question.TestQuestionType.NumberOfAnswers < studentAnswers)
            {
                return(BadRequest("You cheat!"));
            }

            var examAnswersForStudent = await _context.Exams
                                        .Include(ea => ea.ExamAnswer)
                                        .Where(e => e.StudentId == examDto.StudentId &&
                                               e.TestQuestionId == writeAnswersDto.Id)
                                        .ToListAsync();

            //Изтриване на старите отговори ако съществуват
            if (examAnswersForStudent.Count() != 0)
            {
                _context.RemoveRange(examAnswersForStudent);
            }

            //Entities за запис в базата
            ExamAnswer examAnswerToAdd = new ExamAnswer();
            Exam       examToAdd       = new Exam();

            foreach (var answer in writeAnswersDto.Answers)
            {
                //Мапване с въпрос
                var testQuestionAnswerForAdd = await _context.TestQuestionAnswers
                                               .FirstOrDefaultAsync(q => q.Id == answer);

                examAnswerToAdd = new ExamAnswer
                {
                    TestQuestionAnswer = testQuestionAnswerForAdd
                };

                //Проверява дали ид на отговорите дадени от студентът отговарят на тези в базата за въпроса
                var questionsToCheck = question.TestQuestionAnswers.ToList();
                if (!questionsToCheck.Contains(testQuestionAnswerForAdd))
                {
                    return(BadRequest("You cheat"));
                }

                await _context.ExamAnswers.AddAsync(examAnswerToAdd);

                examToAdd = new Exam
                {
                    ExamAnswer   = examAnswerToAdd,
                    Student      = student,
                    TestQuestion = question
                };

                await _context.Exams.AddAsync(examToAdd);
            }

            if (await _context.SaveChangesAsync() > 0)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Пример #21
0
 public async Task <IActionResult> Post([FromBody] ExamAnswer examAnswer)
 {
     // TODO
     return(null);
 }
Пример #22
0
        public ActionResult BulkQuestionDataUpload(FormCollection fc, HttpPostedFileBase questionFile)
        {
            int examId         = int.Parse(fc["examId"]);
            var postedFileBase = Request.Files["questionFile"];

            if (postedFileBase != null && postedFileBase.ContentLength > 0)
            {
                string fileExtension =
                    Path.GetExtension(postedFileBase.FileName);

                if (fileExtension == ".xls" || fileExtension == ".xlsx")
                {
                    var fileLocation = $"{Server.MapPath("~/App_Data/ExportData")}/{postedFileBase.FileName}";

                    if (System.IO.File.Exists(fileLocation))
                    {
                        System.IO.File.Delete(fileLocation);
                    }

                    // ReSharper disable once PossibleNullReferenceException
                    Request.Files["questionFile"].SaveAs(fileLocation);

                    string excelConnectionString;

                    excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation +
                                            ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                    if (fileExtension == ".xls")
                    {
                        excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation +
                                                ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                    }
                    //connection String for xlsx file format.
                    else if (fileExtension == ".xlsx")
                    {
                        excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation +
                                                ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                    } //Create Connection to Excel work book and add oledb namespace

                    OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                    excelConnection.Open();
                    DataTable dt;

                    dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    if (dt == null)
                    {
                        return(null);
                    }

                    String[] excelSheets = new String[dt.Rows.Count];
                    int      t           = 0;
                    //excel data saves in temp file here.
                    foreach (DataRow row in dt.Rows)
                    {
                        excelSheets[t] = row["TABLE_NAME"].ToString();
                        t++;
                    }
                    OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString);
                    DataSet         ds = new DataSet();

                    string query = $"Select * from [{excelSheets[0]}]";
                    using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1))
                    {
                        dataAdapter.Fill(ds);
                    }
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        var kdk = new ExamQuestion
                        {
                            Examination     = _examinationRepository.GetExaminationData(examId),
                            QuestionContent = ds.Tables[0].Rows[i]["Question"].ToString()
                        };

                        var quest = _examinationRepository.SaveQuestion(kdk, null);
                        //add options
                        var eo1 = new ExamOption
                        {
                            OptionContent = ds.Tables[0].Rows[i]["Option1"].ToString(),
                            ExamQuestion  = quest
                        };
                        var op1 = _examinationRepository.SavExamOption(eo1);

                        var eo2 = new ExamOption
                        {
                            OptionContent = ds.Tables[0].Rows[i]["Option2"].ToString(),
                            ExamQuestion  = quest
                        };
                        var op2 = _examinationRepository.SavExamOption(eo2);

                        var eo3 = new ExamOption
                        {
                            OptionContent = ds.Tables[0].Rows[i]["Option3"].ToString(),
                            ExamQuestion  = quest
                        };
                        var op3 = _examinationRepository.SavExamOption(eo3);

                        var eo4 = new ExamOption
                        {
                            OptionContent = ds.Tables[0].Rows[i]["Option4"].ToString(),
                            ExamQuestion  = quest
                        };
                        var op4 = _examinationRepository.SavExamOption(eo4);

                        var eo5 = new ExamOption
                        {
                            OptionContent = ds.Tables[0].Rows[i]["Option5"].ToString(),
                            ExamQuestion  = quest
                        };
                        var op5 = _examinationRepository.SavExamOption(eo5);


                        int value = int.Parse(ds.Tables[0].Rows[i]["Answer"].ToString());
                        //save answer
                        switch (value)
                        {
                        case 1:
                            var ans1 = new ExamAnswer
                            {
                                ExamQuestion = quest,
                                ExamOption   = op1
                            };
                            _examinationRepository.SaveAnswer(ans1);
                            break;


                        case 2:
                            var ans2 = new ExamAnswer
                            {
                                ExamQuestion = quest,
                                ExamOption   = op2
                            };
                            _examinationRepository.SaveAnswer(ans2);
                            break;

                        case 3:
                            var ans3 = new ExamAnswer
                            {
                                ExamQuestion = quest,
                                ExamOption   = op3
                            };
                            _examinationRepository.SaveAnswer(ans3);
                            break;

                        case 4:
                            var ans4 = new ExamAnswer
                            {
                                ExamQuestion = quest,
                                ExamOption   = op4
                            };
                            _examinationRepository.SaveAnswer(ans4);
                            break;

                        case 5:
                            var ans5 = new ExamAnswer
                            {
                                ExamQuestion = quest,
                                ExamOption   = op5
                            };
                            _examinationRepository.SaveAnswer(ans5);
                            break;
                        }
                    }
                    excelConnection.Close();

                    if (System.IO.File.Exists(fileLocation))
                    {
                        System.IO.File.Delete(fileLocation);
                    }

                    TempData["notification"] = "The Questions,Options ans Answers have been uploaded";
                    return(RedirectToAction("Qustion", new { examId }));
                }

                else
                {
                    ModelState.AddModelError("", "Please,select a valid excel file!");
                    ViewBag.examId = examId;

                    return(View(new { id = examId }));
                }
            }

            ModelState.AddModelError("", "Please,select an excel file!");
            ViewBag.examId = examId;

            return(View(new { id = examId }));
        }
Пример #23
0
 /// <summary>
 /// Creates new exam
 /// </summary>
 /// <param name="exam">exam</param>
 /// <returns>void</returns>
 public async Task Create(ExamAnswer exam)
 {
 }
Пример #24
0
 public void appendExamAnswer(ExamAnswer examAnswer)
 {
     examAnswers.Add(examAnswer);
 }
Пример #25
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(ExamAnswer model)
 {
     this._ExamAnswerBiz.Delete(model);
 }
Пример #26
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(ExamAnswer model)
 {
     this._ExamAnswerBiz.Update(model);
 }
Пример #27
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ExamAnswer Insert(ExamAnswer model)
 {
     return(this._ExamAnswerBiz.Insert(model));
 }