コード例 #1
0
        public async Task <int> AddExamAsync(ExamsDTO examsDTO)
        {
            var examToCreate = _mapper.Map <Exam>(examsDTO);
            await _repository.AddExamAsync(examToCreate);

            return(examToCreate.Id);
        }
コード例 #2
0
        public ExamsDTO SaveExams(ExamsDTO exams)
        {
            Exam newExams = _mapper.Map <Exam>(exams);

            _dataContext.Exams.Add(newExams);
            _dataContext.SaveChanges();

            return(_mapper.Map <ExamsDTO>(newExams));
        }
コード例 #3
0
        public async Task <IActionResult> AddExam([FromBody] ExamsDTO examsDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _service.AddExamAsync(examsDTO);

            return(Ok(result));
        }
コード例 #4
0
        public IActionResult UpdateExams(int id, [FromBody] ExamsDTO exams)
        {
            if (ModelState.IsValid)
            {
                var response = _service.PutExams(id, exams);
                return(Ok(response));
            }

            return(BadRequest(ModelState));
        }
コード例 #5
0
        public IActionResult NewExams([FromBody] ExamsDTO exams)
        {
            if (ModelState.IsValid)
            {
                var response = _service.SaveExams(exams);
                return(Created("Exam successfully created", response));
            }

            return(BadRequest(ModelState));
        }
コード例 #6
0
        public ExamsDTO PutExams(int id, ExamsDTO examObject)
        {
            var exam = _dataContext.Exams.FirstOrDefault(x => x.Id == id);

            if (exam == null)
            {
                throw new Exception("Exam not found");
            }

            examObject.Id = id;
            exam          = _mapper.Map <Exam>(examObject);
            _dataContext.SaveChanges();

            return(_mapper.Map <ExamsDTO>(exam));
        }