Add Register and GetAll method

This commit is contained in:
Aurelien 2021-03-30 14:37:23 +01:00
parent 91dd0ef95a
commit 201467f438
1 changed files with 27 additions and 0 deletions

View File

@ -67,6 +67,33 @@ namespace Controllers
Token = tokenString
});
}
[AllowAnonymous]
[HttpPost("register")]
public IActionResult Register([FromBody]RegisterModel model)
{
// map model to entity
var user = _mapper.Map<User>(model);
try
{
// create user
_userService.Create(user, model.Password);
return Ok();
}
catch (AppException ex)
{
// return error message if there was an exception
return BadRequest(new { message = ex.Message });
}
}
[HttpGet]
public IActionResult GetAll()
{
var users = _userService.GetAll();
var model = _mapper.Map<IList<UserModel>>(users);
return Ok(model);
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)