[HttpPut("Edit")]
public async Task<ActionResult> UserEdit([FromBody] UserModel user, string password)
{
var retrievedEntity = _context.Users.Find(user.UserName);
if (retrievedEntity == null) {
return NotFound("User was not found in database");
}
bool changeApproved = Security.VerifyPassword(password, user.Password);
if (!changeApproved) {
return BadRequest("Wrong password");
}
var userEntity = UserServices.ModelToEntity(user);
_context.Users.Update(userEntity);
await _context.SaveChangesAsync();
return Ok("User successfully updated");
}
[HttpPut("Edit")]
public async Task<ActionResult> UserEdit([FromBody] UserModel user, string password)
{
var retrievedEntity = _context.Users.Find(user.UserName);
if (retrievedEntity == null) {
return NotFound("User was not found in database");
}
bool changeApproved = Security.VerifyPassword(password, user.Password);
if (!changeApproved) {
return BadRequest("Wrong password");
}
var userEntity = UserServices.ModelToEntity(user);
_context.Users.Update(userEntity);
await _context.SaveChangesAsync();
return Ok("User successfully updated");
}