mosh-hamedani/vidly-mvc-5

Can't update using Web API

rcdefazio opened this issue · 2 comments

I have been diligently following Mosh's instructions in the Web API section of this course, and everything works in the Web API except for CREATING a new movie or customer and UPDATING an existing movie or customer. My files that affect the operation of my code are attached and include the CustomersController.cs, MoviesController.cs, CustomerDto.cs, MovieDto.cs, WebApiConfig.cs, Global.asax.cs, and MappingProfile.cs. I have read and am uploading the PDF that discussed the issue with assigning the Id value to the CustomerDto or MovieDto object and made sure that my code followed that which is in the GitHub repository. I should note that the PDF says things backward when compared to what is in GitHub, so I would like some clarification regarding the discrepancy.

Finally, it would help if you would also give me the command line to be typed into Postman for purposes of testing these two methods. I know that CREATING a customer or movie requires the POST setting, and UPDATING a customer or movie requires the PUT setting. I am assuming, too, that when updating a movie, the text in the Postman address bar should read something like:

https://localhost:44394/api/movies/4

and the body of the record to be updated should look like:

{
"id": 4,
"name": "Hangover",
"genreTypeId": 1,
"releaseDate": "1980-12-15T00:00:00",
"dateAdded": "1994-03-07T00:00:00",
"numberInStock": 3
}

I am similarly assuming that when CREATING a movie, the text in the Postman address bar should read something like:

https://localhost:44394/api/movies

and the body of the record to be updated should look like:

{
"id": 0,
"name": "Test record",
"genreTypeId": 1,
"releaseDate": "1980-12-15T00:00:00",
"dateAdded": "1994-03-07T00:00:00",
"numberInStock": 1
}

I would appreciate knowing what exactly I am doing wrong such that I can neither CREATE nor UPDATE records in the Customers and Movies tables using the WebApi methods.

Robert DeFazio

GitHubProblem.docx
Section 6 Exercise Solution.pdf

I have found the problem. The problem was not with the code. It was with my understanding of how to use Postman. I was placing the JSON object in the wrong place on the Postman screen and then attempting to update or create. Now that I have reviewed the instructions in the course video, I understand how to do it.

That said, there is still an error in the resource file that Mosh provided to explain how to avoid an error when updating the customerDto.Id field from the customer.Id field. He misstated the line of code, and it should be corrected to prevent confusion on a forward going basis.

I'm wondering where you went wrong because I can post (create) but I can not put (update) movies. Can't figure out what I'm doing wrong, I'm just getting
{
"message": "The requested resource does not support http method 'PUT'."
}