// POST odata/TodoLists public IHttpActionResult Post(TodoList todoList) { if (!ModelState.IsValid) { return BadRequest(ModelState); } todoList.UserId = User.Identity.Name; db.TodoLists.Add(todoList); db.SaveChanges(); return Created(todoList); }
// PUT odata/TodoLists(5) public IHttpActionResult Put([FromODataUri] int key, TodoList todoList) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != todoList.TodoListId || todoList.UserId != User.Identity.Name) { return BadRequest(); } if (!GetTodoListQuery(key).Any()) { return NotFound(); } db.Entry(todoList).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TodoListExists(key)) { return NotFound(); } else { throw; } } return Updated(todoList); }