public async Task <IActionResult> Register(UserDtoForRegisteration userRegistrationDto) { var userToCreate = _mapper.Map <User> (userRegistrationDto); var result = await _userManager.CreateAsync(userToCreate, userRegistrationDto.Password); var userToReturn = _mapper.Map <UserForDetailDto> (userToCreate); if (result.Succeeded) { return(CreatedAtRoute("GetUser", new { controller = "Users", id = userToCreate.Id }, userToReturn)); } return(BadRequest(result.Errors)); }
public async Task <IActionResult> Register(UserDtoForRegisteration userDto) { userDto.Username = userDto.Username.ToLower(); if (await _repo.UserExists(userDto.Username)) { return(BadRequest("Username Already exists!!")); } var newUser = _mapper.Map <User>(userDto); // new User // { // Username = userDto.Username // }; var createdUser = await _repo.RegisterAsync(newUser, userDto.Password); var userToReturn = _mapper.Map <UserForDetailDto>(createdUser); // return StatusCode(201); return(CreatedAtRoute("GetUser", new { controller = "Users", id = createdUser.Id }, userToReturn)); }