// POST api/TodoList public HttpResponseMessage PostTodoList(TodoList todolist) { if (ModelState.IsValid) { db.TodoLists.Add(todolist); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, todolist); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = todolist.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/TodoList/5 public HttpResponseMessage PutTodoList(int id, TodoList todolist) { if (ModelState.IsValid && id == todolist.Id) { db.Entry(todolist).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }