public async Task <int> AddExamAsync(ExamsDTO examsDTO) { var examToCreate = _mapper.Map <Exam>(examsDTO); await _repository.AddExamAsync(examToCreate); return(examToCreate.Id); }
public ExamsDTO SaveExams(ExamsDTO exams) { Exam newExams = _mapper.Map <Exam>(exams); _dataContext.Exams.Add(newExams); _dataContext.SaveChanges(); return(_mapper.Map <ExamsDTO>(newExams)); }
public async Task <IActionResult> AddExam([FromBody] ExamsDTO examsDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _service.AddExamAsync(examsDTO); return(Ok(result)); }
public IActionResult UpdateExams(int id, [FromBody] ExamsDTO exams) { if (ModelState.IsValid) { var response = _service.PutExams(id, exams); return(Ok(response)); } return(BadRequest(ModelState)); }
public IActionResult NewExams([FromBody] ExamsDTO exams) { if (ModelState.IsValid) { var response = _service.SaveExams(exams); return(Created("Exam successfully created", response)); } return(BadRequest(ModelState)); }
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)); }