public async Task<IHttpActionResult> PutPenpal(int id, Penpal penpal) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != penpal.Id) { return BadRequest(); } db.Entry(penpal).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PenpalExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostPenpal(Penpal penpal) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Penpals.Add(penpal); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = penpal.Id }, penpal); }