Hello guys, welcome to the eighth session of the ASP NET Web API tutorial. In the previous lesson, we are retrieving the data from the database as well as inserting new and the upgrading the exit data. In this session we are trying to delete the existing record in the rageful manner folders we need to switch to Visual Studio and create a new accent for delete, public why delete which take only integer ID as a parameter. Like the Apotex and in the relate exam, first of all we need to retrieve the access product and then we need to remove it from the identity. For this we need to use the using statement to create the our product entity object Order order equal to entities or products the first short default x such that x dot product ID is ID that come in the parameter We need to remove this ID from the our entity object entity dot products dot remove and pass the product object and we need to save the our entity object by certain dysfunction.
That's a click on the add on. Let's switch to the postman plugin and use the data request to deleting the hour marker which ID is eight and click on the send button. You can see that it around to zero for no content when we are trying to execute a get request It returned the product with the key when it does not exist message means that the product is successfully removed from the database. You can see that now we need to write this code in the original manner. For that, first of all we need to check whether the product is accessed or not. If product equate corner then we simply need to return the request nor good response at the TP status code dot not found with DMS is brought to you on ID does not exist.
Otherwise, we need to return dot create fresh ones HTTP status code. Okay. Waiting to send the return type to the HTTP response message. Click on the arrow and switch to the postman and execute the request on the ceiling. I can see that it didn't do 200 shaders and whenever we are trying to fire that request That intro done 404 product with the agreement it does not exist My message is the flesh RESTful API in which we are using the data to all of the data and under get excellent for doing the specific item post to add the new item in the database, photo method for updating the existence and delete method for deleting. In this session we are learn how to remove the element first of all we need to read through the exercise and check whether it was exist or not.
If it does not exist, then we need to return the not found status. Otherwise we need to remove it from the our entity and return the orchestrators. Thanks for watching. Have a nice day.