Example #1
0
        public async Task <ExamOutput> InsertAddExam(AddExamInput addExamInput)
        {
            var teacher = await GetTeacher();

            var addExamDto = addExamInput.Adapt <ExamDto>();

            addExamDto.TeacherId = teacher.Id;
            var questions = new List <ExamquestionDto>();

            foreach (var item in addExamInput.Selects)
            {
                var q = item.Adapt <ExamquestionDto>();
                q.QuestionType = QuestionTypeConst.Select;
                questions.Add(q);
            }

            foreach (var item in addExamInput.Singles)
            {
                var q = item.Adapt <ExamquestionDto>();
                q.QuestionType = QuestionTypeConst.Single;
                questions.Add(q);
            }

            foreach (var item in addExamInput.Judges)
            {
                var q = item.Adapt <ExamquestionDto>();
                q.QuestionType = QuestionTypeConst.Judge;
                questions.Add(q);
            }
            addExamDto.Examquestions = questions;

            var exam = await _examService.CreateExam(addExamDto);

            return(exam.Adapt <ExamOutput>());
        }
Example #2
0
        public IActionResult CreateExam([FromBody] ExamViewModel exam)
        {
            var examBlModel = exam.GetBlModel();

            _examService.CreateExam(examBlModel, exam.Classrooms);
            return(NoContent());
        }
Example #3
0
        public HttpResponseMessage CreateExam([FromQuery] CreateExamRequest createExamRequest)
        {
            _examService.CreateExam(new Exam(createExamRequest.CourseId, createExamRequest.ExamDate,
                                             createExamRequest.Room,
                                             createExamRequest.StartTime, createExamRequest.EndTime, createExamRequest.CorrectionScorePostDate,
                                             createExamRequest.Type,
                                             createExamRequest.CorrectionScore));

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Example #4
0
        public IHttpActionResult TakeExam(Exam exam)
        {
            if (!Authorizer.IsAdmin(HttpContext.Current.User.Identity.Name) && string.IsNullOrWhiteSpace(exam.CandidateName))
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            exam.CandidateName = exam.CandidateName ?? HttpContext.Current.User.Identity.Name;

            ViewModels.TestDefinitionDetail test = testRepository.GetTestByID(exam.TestID);

            if (!test.IsPublished)
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            ViewModels.ExamDetail examCreated = examService.CreateExam(test, exam.CandidateName);

            examRepository.UpdateExam(examCreated);

            return(Ok(new { CandidateName = examCreated.CandidateName, TestID = examCreated.TestID, ID = examCreated.ID, Answers = examCreated.Answers.Select(a => new { QuestionID = a.QuestionID }) }));
        }
Example #5
0
        public IHttpActionResult PostExam(Exam exam)
        {
            Exam createdExam = examService.CreateExam(exam);

            return(Created("", createdExam));
        }
Example #6
0
        /// <summary>
        /// Kiểm tra màn hình sau click vào kì thì sẽ là bắt đầu , tiếp tục hay thống kê
        /// </summary>
        /// <param name="termID"></param>
        /// <param name="indexPage"></param>
        /// <param name="sizePage"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public async Task <ActionServiceResult> CheckScreen(string userID, string contestID)
        {
            var res    = new ActionServiceResult();
            var result = await _contestBaseRepository.GetEntityByIdAsync(contestID);

            if (result == null)
            {
                return(null);
            }
            else
            {
                var user = await _userBaseRepository.GetEntityByIdAsync(userID);

                if (user == null)
                {
                    return(null);
                }

                var roleName = string.IsNullOrEmpty(_role.GetValueOrDefault(user.RoleId.ToString())) ? "student" : _role.GetValueOrDefault(user.RoleId.ToString());

                var contestDTO = new ContestDTO();
                var exams      = _examBaseRepository.GetEntitites("Proc_GetExamByContestID", new object[] { contestID }).Result.ToList();
                var exam       = exams.Where(item => item.UserId == Guid.Parse(userID)).FirstOrDefault();

                if (roleName.Equals("student"))
                {
                    if (DateTime.Compare(Utils.GetNistTime(), result.StartTime) < 0)
                    {
                        //Tao de thi
                        if (exam == null)
                        {
                            var exam_new = await _examService.CreateExam(contestID, userID);

                            await _examBaseRepository.AddAsync(exam_new, true);

                            exam = exam_new;
                        }

                        return(new ActionServiceResult(true, "Chưa đến thời gian làm bài", Code.NotTimeToDo, exam.ExamId, 0));
                    }

                    else if (DateTime.Compare(Utils.GetNistTime(), result.FinishTime) > 0)
                    {
                        if (exam == null)
                        {
                            var exam_new = await _examService.CreateExam(contestID, userID);

                            exam_new.Status      = 1;
                            exam_new.Point       = 0;
                            exam_new.CreatedDate = exam_new.ModifiedDate = Utils.GetNistTime();
                            await _examBaseRepository.AddAsync(exam_new, true);

                            contestDTO.ExamID = exam_new.ExamId;
                        }
                        else
                        {
                            contestDTO.ExamID = exam.ExamId;
                        }
                        contestDTO.Continue = 2;
                        return(new ActionServiceResult(true, "Đã hết thời gian làm bài", Code.TimeOut, contestDTO, 0));
                    }
                    else
                    {
                        if (exam == null)
                        {
                            contestDTO.Continue = 0;
                            var exam_new = await _examService.CreateExam(contestID, userID);

                            await _examBaseRepository.AddAsync(exam_new, true);

                            contestDTO.ExamID = exam_new.ExamId;
                            //Tao bai thi
                        }
                        else
                        {
                            contestDTO.ExamID = exam.ExamId;
                            if (exam.IsDoing == 1 && DateTime.Compare(Utils.GetNistTime(), exam.ModifiedDate.Value) > 0 && exam.Status == 0)
                            {
                                contestDTO.Continue = 1;
                            }
                            if (exam.Status == 1)
                            {
                                contestDTO.Continue = 2;
                            }
                        }
                    }

                    res.Data = contestDTO;
                }
                else
                {
                    if (DateTime.Compare(Utils.GetNistTime(), result.FinishTime) < 0)
                    {
                        var data = new
                        {
                            NumOfJoining = exams.Count(item => item.IsDoing == 1)
                        };
                        return(new ActionServiceResult(true, "Đang trong thời gian làm bài", (Code)1001, data, 0));
                    }
                    else
                    {
                        return(new ActionServiceResult(true, "", (Code)1001, exams, 0));
                    }
                }
            }

            return(res);
        }