Skip to content

Instantly share code, notes, and snippets.

@corespider
Created August 14, 2020 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corespider/ace52a68f101fe82a8fdd2bf15da28d6 to your computer and use it in GitHub Desktop.
Save corespider/ace52a68f101fe82a8fdd2bf15da28d6 to your computer and use it in GitHub Desktop.
ASP NET CRUD Web API Post Customer
[ResponseType(typeof(Customer))]
public IHttpActionResult PostCustomer(Customer customer)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Customers.Add(customer);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = customer.CustId }, customer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment