public IHttpActionResult PostCategory(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Categories.Add(category); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = category.CategoryId }, category); }
public IHttpActionResult PutCategory(int id, Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != category.CategoryId) { return BadRequest(); } // db.Entry(category).State = EntityState.Modified; db.MarkAsModified(category); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void Add(Category b) { context.Categories.Add(b); context.SaveChanges(); }
public void Edit(Category b) { context.Entry(b).State = System.Data.Entity.EntityState.Modified; }
public void MarkAsModified(Category item) { }