public IActionResult PostStudent([FromBody] PostStudentDTO body)
        {
            var newStudent = _mapper.Map <Student>(body);

            _uow.Repository <Student>().Add(newStudent);

            if (!_uow.Complete(1))
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(CreatedAtRoute("GetStudent", new { id = newStudent.Id }, _mapper.Map <SimpleStudentDTO>(newStudent)));
        }
示例#2
0
        public IActionResult PostStudent([FromBody] PostStudentDTO body)
        {
            try
            {
                var newStudent = _mapper.Map <Student>(body);
                _uow.StudentRepository.Create(newStudent);

                _uow.Complete(false);
                return(CreatedAtRoute("GetStudent", new { id = newStudent.Id }, _mapper.Map <StudentDTO>(newStudent)));
            }
            catch (Exception e)
            {
                _logger.LogError($"Error in action `PostStudent()`. {e.Message}");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }