public async Task <IActionResult> CreateStudentAsync([FromBody] NewStudentViewModel student) { if (!ModelState.IsValid) { return(BadRequest(new ValidationError(ModelState))); } var newStudent = await _studentsService.CreateStudentAsync(_mapper.Map <StudentDto>(student)); return(CreatedAtRoute("GetStudent", new { studentId = newStudent.Id }, newStudent)); }
public async Task <ActionResult <StudentResource> > CreateStudent( [FromBody] SaveStudentResource saveStudentResource) { var studentDtoToCreate = _mapper.Map <StudentDto>(saveStudentResource); var newStudentDto = await _studentService.CreateStudentAsync(studentDtoToCreate); var createdStudentDto = await _studentService.GetStudentByIdAsync(newStudentDto.Id); var studentResource = _mapper.Map <StudentResource>(createdStudentDto); return(Ok(studentResource)); }
public async Task <IActionResult> CreateStudent(CreateStudentRequest student) { await _studentsService.CreateStudentAsync(student); return(NoContent()); }