Beispiel #1
0
 public InvoiceLineModel(ExamDto dto, decimal amount)
 {
     Exam   = dto;
     Amount = amount;
 }
Beispiel #2
0
        public JsonResult RemoveExamByCode(ExamDto dto)
        {
            var result = _examManager.RemoveExamByCode(dto.Code, dto.CourseId);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
 public void setModel(ExamDto dto)
 {
     ((IExamInputViewModel)DataContext).UpdateModel(dto);
 }
Beispiel #4
0
 public async Task <ExamDto> CreateOrUpdateExam(ExamDto exam)
 {
     return(await _service.CreateOrUpdateExam(exam));
 }
Beispiel #5
0
 public IActionResult Add(ExamDto examDto)
 {
     _examService.Add(examDto);
     return(StatusCode(201));
 }
Beispiel #6
0
        public void Add(ExamDto examDto)
        {
            Exam exam = examDto.ExamMapping();

            _examDal.Add(exam);
        }
Beispiel #7
0
        public void Update(ExamDto examDto)
        {
            Exam exam = examDto.ExamMapping();

            _examDal.Update(exam);
        }
Beispiel #8
0
 public AddExamCommand(ExamDto exam)
 {
     Exam = exam;
 }
Beispiel #9
0
 public Task <ExamDto> CreateOrUpdateExam(ExamDto dto)
 {
     throw new NotImplementedException();
 }
        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());
        }
Beispiel #11
0
 public void  addExam(ExamDto dto)
 {
     ((IInvoiceInputViewModel)DataContext).AddExam(dto);
 }
Beispiel #12
0
 public void Update([FromBody] ExamDto examDto)
 {
     _examService.Update(examDto);
 }