ASP NET CRUD Web API Put customer data
[ResponseType(typeof(void))] | |
public IHttpActionResult PutCustomer(int id, Customer customer) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
return BadRequest(ModelState); | |
} | |
if (id != customer.CustId) | |
{ | |
return BadRequest(); | |
} | |
db.Entry(customer).State = EntityState.Modified; | |
try | |
{ | |
db.SaveChanges(); | |
} | |
catch (DbUpdateConcurrencyException) | |
{ | |
if (!CustomerExists(id)) | |
{ | |
return NotFound(); | |
} | |
else | |
{ | |
throw; | |
} | |
} | |
return StatusCode(HttpStatusCode.NoContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment