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