public async Task <IActionResult> Register([FromBody] UserForRegisterDto userForRegisterDto) { //validate request if (!ModelState.IsValid) { return(BadRequest(ModelState)); } userForRegisterDto.Username = userForRegisterDto.Username.ToLower(); if (await _repo.UserExists(userForRegisterDto.Username)) { return(BadRequest("Username already exists")); } var userToCreate = new User { UserName = userForRegisterDto.Username, }; var createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password); return(StatusCode(201)); }
public async Task <IActionResult> Register(UserForRegisterDTO userDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } userDto.UserName = userDto.UserName.ToLower(); if (await _repo.UserExists(userDto.UserName)) { return(BadRequest("UserName already exists")); } var userToCreate = _mapper.Map <User>(userDto); var createduser = await _repo.Register(userToCreate, userDto.PassWord); var userToReturn = _mapper.Map <UserForDetailsDto>(createduser); return(CreatedAtRoute("GetUser", new { Controller = "Users", id = createduser.Id }, userToReturn)); }