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