public IActionResult AddCategory(Category category) { using var context = new WebApiCrudContext(); context.Categories.Add(category); context.SaveChanges(); return(Created("", category)); }
public IActionResult DeleteCategory(int id) { using var context = new WebApiCrudContext(); var deletedCategory = context.Categories.Find(id); if (deletedCategory == null) { return(NotFound()); } context.Remove(deletedCategory); context.SaveChanges(); return(NoContent()); }
public IActionResult UpdateCategory(Category c) { using var context = new WebApiCrudContext(); var updatecategory = context.Categories.Find(c.Id); if (updatecategory == null) { return(NotFound()); } updatecategory.Name = c.Name; context.Update(updatecategory); context.SaveChanges(); return(NoContent()); }