From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Updating and deleting an entity

Updating and deleting an entity

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Updating and deleting an entity

- Before we move to the next chapter, let us see how we can update or delete an entity. For that, let's go to Visual Studio and see it in action. Let us start with the updating an entity. So for that we need to go to our controller and scroll down after the Post request. In here let's write public async task of IHttp action result, and then we write in here Put. These takes two parameters. The first parameter is going to come from the URL, which is the identifier for the entity, and the second parameter is going to be the entity with the updated values. So, let's write in here FromODataUri, and this is going to be the key of type integer, the second parameter is going to be a student entity. We need to first check two things. First thing that we need to check is if the student entity has valid data, and the next, we need to check if the student's ID is equal to the ID that we have in our URL. Let us start with the model…

Contents