public IHttpActionResult PutTodo(int id, Todo todo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != todo.TodoId) { return BadRequest(); } db.Entry(todo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TodoExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostTodo(Todo todo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Todoes.Add(todo); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = todo.TodoId }, todo); }