public State Create(State state) {
     if (state == null) {
         throw new ArgumentNullException("state");
     }
     state.Id = _nextId++;
     _states.Add(state);
     return state;
 }
 public int Update(State state) {
     if (state == null) {
         throw new ArgumentNullException("state");
     }
     int index = _states.FindIndex(e => e.Id == state.Id);
     if (index == -1) {
         return 0;
     }
     _states.RemoveAt(index);
     _states.Add(state);
     return 1;
 }
 // PUT /api/State/3
 public HttpResponseMessage Put(int Id, State state)
 {
     if (ModelState.IsValid) {
         try {
             int numRowsAffected = _stateRepository.Update(state);
             var response = Request.CreateResponse<CrudResult>(HttpStatusCode.OK, new CrudResult(CrudStatusCode.Success, numRowsAffected, new List<State> { state }));
             string uri = Url.Link("DefaultApi", new { Id = state.Id });
             response.Headers.Location = new Uri(uri);
             return response;
         }
         catch (Exception ex) {
             return Request.CreateErrorResponse(HttpStatusCode.NotModified, ex.Message);
         }
     }
     else {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }