// PUT api/TodoItem/5 public async Task<IHttpActionResult> PutTodoItem(int id, TodoItem todoitem) { if (!ModelState.IsValid) { return this.BadRequest(this.ModelState); } if (id != todoitem.TodoItemId) { return this.BadRequest(); } this.db.Entry(todoitem).State = EntityState.Modified; try { await this.db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.TodoItemExists(id)) { return this.NotFound(); } else { throw; } } return this.StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostTodoItem(TodoItem todoitem) { if (!ModelState.IsValid) { return this.BadRequest(this.ModelState); } this.db.TodoItems.Add(todoitem); await this.db.SaveChangesAsync(); return this.CreatedAtRoute("DefaultApi", new { id = todoitem.TodoItemId }, todoitem); }