public HttpResponseMessage Post(Users user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = user.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public HttpResponseMessage Put(int id, Users user) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != user.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }