public async Task<IHttpActionResult> PutContributor(int id, Contributor contributor) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != contributor.Id) { return BadRequest(); } contributor.Projects.ForEach(p => db.Projects.Attach(p)); db.UpdateGraph(contributor, map => map.AssociatedCollection(c => c.Projects)); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContributorExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostContributor(Contributor contributor) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Contributors.Add(contributor); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = contributor.Id }, contributor); }