// POST api/City public HttpResponseMessage PostCity(City city) { if (ModelState.IsValid) { db.Cities.Add(city); city.InsertBy = loginUser.UserID; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, city); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = city.CityID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/City/5 public HttpResponseMessage PutCity(long id, City city) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != city.CityID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } city.Country = null; city.UpdateBy=loginUser.UserID; db.Entry(city).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }