public IActionResult Post(Category category) { using var context = new ProjectWebApiContext(); context.Categories.Add(category); context.SaveChanges(); return(Created("", category)); }
public IActionResult Delete(int id) { using var context = new ProjectWebApiContext(); var deletedCategory = context.Categories.Find(id); if (deletedCategory == null) { return(NotFound()); } context.Remove(deletedCategory); context.SaveChanges(); return(NoContent()); }
public IActionResult UpdateCategory(Category category) { using var context = new ProjectWebApiContext(); var updatedCategory = context.Find <Category>(category.Id); if (updatedCategory == null) { return(NotFound()); } updatedCategory.Name = category.Name; context.Update(updatedCategory); context.SaveChanges(); return(NoContent()); }