public async Task<IHttpActionResult> PostCollection(Collection collection) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Collection.Add(collection); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CollectionExists(collection.UserID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = collection.UserID }, collection); }
public async Task<IHttpActionResult> PutCollection(int id, Collection collection) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != collection.UserID) { return BadRequest(); } db.Entry(collection).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CollectionExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }