示例#1
0
        public IActionResult Register([FromBody] InstructorRegisterDto instructor)
        {
            if (_service.IsUserExist(instructor.UserName))
            {
                ModelState.AddModelError("UserName", "Username already taken");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var instructorToCreate = new Instructor()
            {
                DepartmentId = instructor.DepartmentId,
                User         = new User()
                {
                    Name     = instructor.Name,
                    Surname  = instructor.Surname,
                    UserName = instructor.UserName,
                    Email    = instructor.Email
                }
            };

            _service.Register(instructorToCreate, instructor.Password);
            // 201: Created Status
            return(StatusCode(201));
        }