コード例 #1
0
        public IActionResult Post([FromBody] StudentForCreationDto studentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var studentEntity = Mapper.Map <Student>(studentDto);

            studentEntity.Alias = "@" + studentEntity.Lastname + " " + studentEntity.Name;
            _studentInfoRepository.AddStudent(studentEntity);
            if (!_studentInfoRepository.Save())
            {
                return(StatusCode(500, "Could not save in DB"));
            }
            var CreatedUser = Mapper.Map <StudentDto>(studentEntity);

            return(Ok());//CreatedAtRoute("coursess({key})", new { = studentEntity.Alias}, CreatedUser);
        }
コード例 #2
0
        public IActionResult AddUsers([FromBody] StudentForCreationDto studentDto)
        {
            if (studentDto == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var studentEntity = Mapper.Map <Student>(studentDto);

            studentEntity.Alias = "@" + studentEntity.Lastname + " " + studentEntity.Name;
            _studentInfoRepository.AddStudent(studentEntity);
            if (!_studentInfoRepository.Save())
            {
                return(StatusCode(500, "Could not save in DB"));
            }
            var CreatedUser = Mapper.Map <StudentDto>(studentEntity);

            return(CreatedAtRoute("GetStudent", new { studentId = studentEntity.Alias }, CreatedUser));
        }