// PATCH odata/Suppliers('CTSO') public async Task<IHttpActionResult> Patch([FromODataUri] string key, Supplier patchSupplier) { if (!ModelState.IsValid || key != patchSupplier.Key) { return BadRequest(ModelState); } var supplier = await db.Suppliers.FindAsync(key); if (supplier == null) { return NotFound(); } if (!String.IsNullOrEmpty(patchSupplier.Name)) { supplier.Name = patchSupplier.Name; } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { Debug.WriteLine(ex); return NotFound(); } return Ok(supplier); }
// POST odata/Suppliers public async Task<IHttpActionResult> Post(Supplier supplier) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Suppliers.Add(supplier); await db.SaveChangesAsync(); var location = new Uri(Url.Link("ODataRoute", new { key = supplier.Key })); return Created(location, supplier); }
// PUT odata/Suppliers('CTSO') public async Task<IHttpActionResult> Put([FromODataUri] string key, Supplier supplier) { if (!ModelState.IsValid || key != supplier.Key) { return BadRequest(ModelState); } db.Entry(supplier).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { Debug.WriteLine(ex); return NotFound(); } return Ok(supplier); }