Wednesday, August 14, 2019

Creating a PUT (Update) method in Asp.Net Core WebAPI Controller

In this post we will create a HttpPut method in Asp.Net Core WebAPI, which will be used to update a row in the SQL Server database using Entity Framework Core. We have seen how to setup Entity Framework Core in an Asp.Net Core Web API project in the previous posts, in this post we will jump into creating the HttpPut method.

Open the Country controller which we used in the previous post and add the following Update method which uses the HttpPut verb.

        [HttpPut]
        public void Update(Country country)
        {
            var _context = new UserRegistrationContext();
            _context.Country.Update(country);
            _context.SaveChanges();

        }

Once the method is writer build and run the project, we can invoke the Update method using Postman as follows.


This will update the value of France to France-Updated in the SQL server database, you can verify this by running the GET method again which will return the updated list as follows.




Search Flipkart Products:
Flipkart.com

No comments: