// PUT api/Roles/5 public HttpResponseMessage Putroles(int id, roles roles) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != roles.id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(roles).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Roles public HttpResponseMessage Postroles(roles roles) { if (ModelState.IsValid) { db.roles.Add(roles); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, roles); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = roles.id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }