public IActionResult UpdateStudent(string studentId, [FromBody] StudentForCreatingDto student) { var studentFromRepo = _repository.GetStudent(studentId); if (studentFromRepo == null) { // Student not exists, by REST PUT we must create new student var studentToAdd = _mapper.Map <Entities.Student>(student); studentToAdd.Id = studentId; _repository.AddStudent(studentToAdd); _repository.Save(); var studentToReturn = _mapper.Map <StudentDto>(studentToAdd); return(CreatedAtRoute("GetStudent", new { studentId = studentToReturn.Id }, studentToReturn)); } // course exist, we update one _mapper.Map(student, studentFromRepo); _repository.UpdateStudent(studentId, studentFromRepo); _repository.Save(); return(NoContent()); }
public ActionResult <StudentDto> Create([FromBody] StudentForCreatingDto studentForCreatingDto) { var studentEntity = _mapper.Map <Entities.Student>(studentForCreatingDto); _repository.AddStudent(studentEntity); _repository.Save(); var studentToReturn = _mapper.Map <StudentDto>(studentEntity); return(CreatedAtRoute("GetStudent", new { studentId = studentToReturn.Id }, studentToReturn)); }