Skip to content

Commit 68a6ace

Browse files
FabianGosebrinkFabianGosebrink
authored andcommitted
Fixed Patch-Action
1 parent 115d068 commit 68a6ace

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/SampleWebApiMVC6/Controllers/HouseController.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public IActionResult GetSingle(int id)
3838
return new JsonResult(_houseMapper.MapToDto(houseEntity));
3939
}
4040

41-
[HttpPatch]
42-
public IActionResult Patch(int id, [FromBody] JsonPatchDocument<HouseDto> housePatchDocument)
41+
[HttpPatch("{id}")]
42+
public IActionResult Patch(int id, [FromBody] JsonPatchDocument<HouseEntity> housePatchDocument)
4343
{
4444
if (housePatchDocument == null)
4545
{
@@ -53,19 +53,17 @@ public IActionResult Patch(int id, [FromBody] JsonPatchDocument<HouseDto> houseP
5353

5454
HouseEntity houseEntity = Singleton.Instance.Houses.FirstOrDefault(x => x.Id == id);
5555

56-
HouseDto existingHouse = _houseMapper.MapToDto(houseEntity);
57-
58-
housePatchDocument.ApplyTo(existingHouse, ModelState);
56+
housePatchDocument.ApplyTo(houseEntity, ModelState);
5957

6058
if (!ModelState.IsValid)
6159
{
6260
return HttpBadRequest(ModelState);
6361
}
6462

6563
int index = Singleton.Instance.Houses.FindIndex(x => x.Id == id);
66-
Singleton.Instance.Houses[index] = _houseMapper.MapToEntity(existingHouse);
64+
Singleton.Instance.Houses[index] = houseEntity;
6765

68-
return new JsonResult(existingHouse);
66+
return new JsonResult(_houseMapper.MapToDto(houseEntity));
6967
}
7068

7169
[HttpPost]

0 commit comments

Comments
 (0)