Exemple #1
0
        public void Delete(int id)
        {
            var tempExam = _examRepository.Get(id);

            tempExam.IsDeleted = true;
            _examRepository.Update(tempExam);
        }
Exemple #2
0
 public bool VerifyPassword(AccessExamDTO access)
 {
     if (examService.IsRandom(access.Id))
     {
         return(examRepository.GetRandomExam(access.Id).Password == access.Password);
     }
     return(examRepository.Get(access.Id).Password == access.Password);
 }
Exemple #3
0
        public IActionResult Index(int examId)
        {
            List <ExamQuestion> examQuestions = examQuestionRepository.GetExamQuestions(examId);

            //List<QuestionChoice> questionChoices =questionChoiceRepository.GetQuestionChoices()
            ViewBag.Exam   = examRepository.Get(examId);
            ViewBag.ExamId = examId;
            return(View(examQuestions));
        }
Exemple #4
0
        public async Task <IActionResult> getExam(int id)
        {
            var exam = await _exam.Get(id);

            if (exam == null)
            {
                return(NotFound());
            }
            return(Ok(exam));
        }
        public IActionResult Update(int courseId, int examId)
        {
            Exam          exam  = examRepository.Get(examId);
            ExamViewModel model = new ExamViewModel
            {
                CourseId  = courseId,
                Duration  = exam.Duration,
                EndDate   = exam.EndDate,
                StartDate = exam.StartDate,
                Name      = exam.Name,
                Id        = exam.Id
            };

            ViewBag.Course = courseRepository.Get(courseId);
            ViewBag.examId = courseRepository.Get(examId);
            return(View(model));
        }
Exemple #6
0
 public IActionResult getExamInformation(int idLesson)
 {
     try
     {
         return(new ObjectResult(_exam.Get(idLesson)));
     }
     catch
     {
         return(BadRequest());
     }
 }
Exemple #7
0
        public ExamWithQuestionsDTO Get(Guid Id) // Id of Exam
        {
            List <QuestionDTO> questionList = new List <QuestionDTO>();
            List <Question>    questions    = questionRepository.ListByExamId(Id);

            foreach (var question in questions)
            {
                // add answer to Questions
                List <AnswerDTO> answerDTOs = new List <AnswerDTO>();
                List <Answer>    answers    = answerRepository.ListByQuestionId(question.Id);
                foreach (var answer in answers)
                {
                    answerDTOs.Add(new AnswerDTO
                    {
                        Content   = answer.Content,
                        IsCorrect = answer.IsCorrect
                    });
                }

                // add question to List
                questionList.Add(new QuestionDTO
                {
                    Id         = question.Id,
                    Difficulty = question.Difficulty,
                    Type       = question.Type,
                    Content    = question.Content,
                    Answers    = answerDTOs
                });
            }
            Exam exam = examRepository.Get(Id);

            return(new ExamWithQuestionsDTO
            {
                Name = exam.Name,
                Time = exam.Time,
                Questions = questionList
            });
        }
        public IActionResult TakeExam(int examID)
        {
            TakeExamViewModel takeExam = new TakeExamViewModel();
            var Exam = examRepository.Get(examID);
            List <ExamQuestion> examQuestions = examQuestionRepository.GetExamQuestions(examID).ToList();

            takeExam.Questions = examQuestions.Select(c => c.Question).ToList();

            if (takeExam.Questions.Count == 0)
            {
                return(RedirectToAction("NotExistExam"));
            }
            takeExam.ExamId       = examID;
            takeExam.ExamDuration = Exam.Duration;
            int startDateCompare = DateTime.Compare(Exam.StartDate, DateTime.Now);
            int endDateCompare   = DateTime.Compare(Exam.EndDate, DateTime.Now);

            //if (startDateCompare < 0 && endDateCompare > 0)
            //{
            // return RedirectToAction("NotExistExam");
            // }
            return(View(takeExam));
        }
Exemple #9
0
 public ISet <Exam> GetAllExams() => _examRepository.Get();
        public StatisticsDTO GetStatistics(Guid examId)
        {
            List <Score> scores = scoreRepository.ListByExamId(examId);

            if (scores.Count == 0)
            {
                return(new StatisticsDTO
                {
                    Participants = 0,
                    AvgScore = 0,
                    AvgTimeSpent = "0 phút 0 giây"
                });
            }
            StatisticsDTO response   = new StatisticsDTO();
            TimeSpan      totalTime  = TimeSpan.Zero;
            double        totalScore = 0;
            TimeSpan      examTime   = TimeSpan.FromMinutes(int.Parse(examService.IsRandom(examId) ? examRepository.GetRandomExam(examId).Time : examRepository.Get(examId).Time));

            scores.ForEach(x =>
            {
                totalTime  += x.Time.Equals("") ? examTime : TimeSpan.Parse(x.Time);
                totalScore += x.Score1;
            });
            double avgTimeInSecond = totalTime.TotalSeconds / scores.Count;

            response.Participants = scores.Count;
            response.AvgScore     = response.Participants == 0 ? 0 : Math.Round(totalScore / response.Participants, 2, MidpointRounding.AwayFromZero);
            response.AvgTimeSpent = ((int)(avgTimeInSecond / 60)) + " phút " + ((int)(avgTimeInSecond % 60)) + " giây";
            return(response);
        }
        public void Delete(Guid userId, Guid examId)
        {
            var ownerId = examService.IsRandom(examId) ? examRepository.GetRandomExam(examId).OwnerId : examRepository.Get(examId).OwnerId;

            if (ownerId == userId)
            {
                scoreRepository.Delete(userId, examId);
            }
        }