Esempio n. 1
0
 public ExamControllerTests()
 {
     createExamModel = new CreatingExamModel();
     updateExamModel = new UpdateExamModel();
     mockRepo        = new Mock <IExamService>();
     mockRepoGrade   = new Mock <IGradeService>();
     //controller = new ExamsController(mockRepo.Object,mockRepoGrade.Object);
 }
        public async Task <IActionResult> CreateExam([FromBody] CreatingExamModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Todo: need to check all fields before entering a new one.
            // Todo: Exams with the same date, but with different rooms, are two separate exams
            var exam = examService.FindByTime(model.Date);

            if (exam.Result == null)
            {
                var examId = await examService.CreateNew(model);

                return(StatusCode(StatusCodes.Status201Created, examId));
            }

            return(Conflict());
        }
Esempio n. 3
0
        public async Task<IActionResult> CreateExam([FromBody] CreatingExamModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // Todo: need to check all fields before entering a new one. 
            // Todo: Exams with the same date, but with different rooms, are two separate exams
            var exam = examService.FindByTimeAndRoomAndType(model.Date, model.Room, model.Type, model.CourseId);
            if (exam.Result == null)
            {
            var examId = await examService.CreateNew(model);
            var students = await courseService.getAllStudentsByCourse(model.CourseId);
            await examService.AssignStudentsToExam(examId, students);
            return StatusCode(StatusCodes.Status201Created, examId);
            }

            return Conflict();
        }