public HttpResponseMessage PostCategory(Category category) { db.Categories.Add(category); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, category); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = category.Id })); return response; }
public HttpResponseMessage PutCategory(int id, Category category) { if ( id == category.Id) { db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }