public IHttpActionResult PostManufacturer(Manufacturer manufacturer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Manufacturer.Add(manufacturer); try { db.SaveChanges(); } catch (DbUpdateException) { if (ManufacturerExists(manufacturer.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = manufacturer.Id }, manufacturer); }
public IHttpActionResult PutManufacturer(int id, Manufacturer manufacturer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != manufacturer.Id) { return BadRequest(); } db.Entry(manufacturer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ManufacturerExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }