public async Task<IHttpActionResult> PutToDoItem(long id, ToDoItem toDoItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != toDoItem.Id) { return BadRequest(); } db.Entry(toDoItem).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostToDoItem(ToDoItem toDoItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.ToDos.Add(toDoItem); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = toDoItem.Id }, toDoItem); }