Example #1
0
        public async Task <IActionResult> DoExam(int id)
        {
            var examQuery = await _repo.GetOneWithManyToMany <Exam>(exam => exam.Id == id);

            var exam = await examQuery.Include(e => e.Questions).ThenInclude(q => q.Question).FirstOrDefaultAsync();

            if (exam == null)
            {
                return(NotFound());
            }
            var returnExam = _mapper.Map <ExamDTO>(exam);

            returnExam.Questions = returnExam.Questions.OrderBy(q => q.ToeicPart);
            if (User.FindFirst(ClaimTypes.NameIdentifier) != null)
            {
                int userId    = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                var histories = await _repo.GetOneWithCondition <ExamHistory>(e => e.ExamId == id && e.AccountId == userId && e.IsDoing);

                if (histories == null)
                {
                    var history = new ExamHistory()
                    {
                        AccountId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value),
                        ExamId    = id,
                        Start_At  = DateTime.Now,
                        IsDoing   = true
                    };
                    _repo.Create(history);
                    await _repo.SaveAll();
                }
                return(Ok(returnExam));
            }
            return(Ok(returnExam));
        }
Example #2
0
        public void GetExamHistoryByIDTest()
        {
            PaymentService_Accessor target = new PaymentService_Accessor(); // TODO: Initialize to an appropriate value
            string idCard   = "3500700477390";                              // TODO: Initialize to an appropriate value
            string expected = string.Empty;                                 // TODO: Initialize to an appropriate value

            string      actual;
            ExamHistory ex = new ExamHistory();

            expected = "502123";
            actual   = target.GetExamHistoryByID(idCard);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public void finalizeExam()
        {
            ExamHistory exam = new ExamHistory();

            exam.ExamId    = examId;
            exam.UserId    = userId;
            exam.TakenDate = startDateTime;
            exam.Result    = this.getScorePercent() / 100;

            using (var context = new ExamsDBContext())
            {
                context.ExamHistory.Add(exam);
                context.SaveChanges();
            }
        }