// PUT odata/Customers(5) public async Task <IHttpActionResult> Put([FromODataUri] Guid key, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != customer.CustomerID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(key)) { return(NotFound()); } else { throw; } } return(Updated(customer)); }
// PUT odata/Products(5) public async Task <IHttpActionResult> Put([FromODataUri] int key, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != product.ProductID) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(key)) { return(NotFound()); } else { throw; } } return(Updated(product)); }
// POST odata/TodoItems public async Task <IHttpActionResult> Post(TEntity item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Items.Add(item); await _context.SaveChangesAsync(); return(Created(item)); }