1
0
mirror of https://github.com/XFox111/PhonebookService.git synced 2026-04-22 06:29:55 +03:00

Added entry existance check for Update endpoint

This commit is contained in:
Eugene Fox
2023-02-22 17:26:42 +03:00
parent 7ec91469e3
commit af882e6863
@@ -69,6 +69,11 @@ public class PhonebookController : Controller
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateItemAsync(int id, [FromBody]PhonebookRecord item)
{
PhonebookRecord? entry = await _book.GetItemByIdAsync(id);
if (entry is null)
return NotFound();
ValidationResult result = await _validator.ValidateAsync(item);
if (!result.IsValid)
@@ -80,7 +85,7 @@ public class PhonebookController : Controller
}
item.Id = id;
PhonebookRecord entry = await _book.UpdateItemAsync(item);
entry = await _book.UpdateItemAsync(item);
return Json(entry);
}