From 35a19ce489851d00dfeacb0490c35aa6e73849fc Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 19 Oct 2020 23:38:33 -0400 Subject: [PATCH] update route --- Controllers/PeopleController.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Controllers/PeopleController.cs b/Controllers/PeopleController.cs index 0d145b0..62c8cbd 100644 --- a/Controllers/PeopleController.cs +++ b/Controllers/PeopleController.cs @@ -72,5 +72,24 @@ namespace contacts.Controllers } } + + [HttpPut] + [Route("{id}")] + public Person[] Put(int id, [FromBody]Person updatedPerson) + { + using (var db = new PeopleContext()) + { + var foundPerson = db.People.SingleOrDefault(person => person.PersonId == id); + foundPerson.Name = updatedPerson.Name; + foundPerson.Age = updatedPerson.Age; + db.SaveChanges(); + + var people = db.People + .OrderBy(person => person.PersonId) + .ToArray(); + return people; + + } + } } }