public async Task<IHttpActionResult> PutCategory(int id, Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != category.Id) { return BadRequest(); } db.Entry(category).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void ListViewCategories_InsertItem() { var item = new Category(); TryUpdateModel(item); if (ModelState.IsValid) { this.dbContext.Categories.Add(item); this.dbContext.SaveChanges(); } }
public async Task<IHttpActionResult> PostCategory(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Category.Add(category); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = category.Id }, category); }
private bool CreateCategori() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Models.Category newcategori = new Models.Category { Name = txtNameCategori.Text }; db.Categories.Add(newcategori); db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }