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