如何将数据传递到postman中的动词HttpPut
我在api控制器中有以下方法来更新数据库的记录。如何使用动词PUT将记录传递给postman中的update,以及如何将record for update传递给方法UpdateEmployee from postman如何将数据传递到postman中的动词HttpPut,postman,http-put,Postman,Http Put,我在api控制器中有以下方法来更新数据库的记录。如何使用动词PUT将记录传递给postman中的update,以及如何将record for update传递给方法UpdateEmployee from postman [HttpPut] public IActionResult UpdateEmployee([FromBody] Employee employee) { if (employee == null) return BadRequest(); if
[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"
}