Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateStudent(CreateStudentRequest student)
        {
            await _studentsService.CreateStudentAsync(student);

            return(NoContent());
        }