我的api控制器中具有以下方法来更新数据库的记录。如何使用动词PUT传递记录以在邮递员中进行更新,以及如何将记录更新以从邮递员传递给UpdateEmployee方法
[HttpPut]
public IActionResult UpdateEmployee([FromBody] Employee employee)
{
if (employee == null)
return BadRequest();
if (employee.FirstName == string.Empty || employee.LastName == string.Empty)
{
ModelState.AddModelError("Name/FirstName", "The name or first name shouldn't be empty");
}
if (!ModelState.IsValid)
return BadRequest(ModelState);
var employeeToUpdate = _employeeRepository.GetEmployeeById(employee.EmployeeId);
if (employeeToUpdate == null)
return NotFound();
_employeeRepository.UpdateEmployee(employee);
return NoContent(); //success
}
我有以下数据
{
"employeeId": 1,
"firstName": "Test",
"lastName": "Name",
"birthDate": "1979-01-16T00:00:00",
"email": "test@gmail.com",
"street": "Grote Markt 1",
"zip": "1000",
"city": "Brussels",
"countryId": 1,
"country": null,
"phoneNumber": "324777888773"
}