Answer the question
In order to leave comments, you need to log in
How to assign an id to a model?
Explain, please. Here I am writing a service for user registration, everything is fine.
BUT! After that, when I send a request to Postman, it displays to me that the request has been processed. But, the most important thing is that the new user didn't push...
What's wrong? What am I missing?
public async Task<UserDto> Register(UserDto userModel, string password)
{
if (!await EmailExists(userModel.Email)) return null;
byte[] passwordHash, passwordSalt;
HashPassword(password, out passwordHash, out passwordSalt);
var user = _mapper.Map<User>(userModel);
user .PasswordHash = passwordHash;
user .PasswordSalt = passwordSalt;
var createdUser= await _unitOfWork.UserRepository.AddAsync(user );
return _mapper.Map<userModel>(createdUser);
}
public async Task<IActionResult> Register([FromBody] UserRegistrationModel userRegistrationModel)
{
var user = _mapper.Map<UserDto>(userRegistrationModel);
await _authService.Register(user , userRegistrationModel.Password);
//return CreatedAtAction(nameof(Login), user );
return CreatedAtAction(nameof(Login), new { id = user .Id }, userRegistrationModel);
}
Answer the question
In order to leave comments, you need to log in
public async Task<IActionResult> Register([FromBody] UserRegistrationModel userRegistrationModel)
{
var user = _mapper.Map<UserDto>(userRegistrationModel);
var newUser = await _authService.Register(user , userRegistrationModel.Password);
//return CreatedAtAction(nameof(Login), user );
return CreatedAtAction(nameof(Login), new { id = newUser .Id }, userRegistrationModel);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question