示例#1
0
 public IActionResult AddCategory(Category category)
 {
     using var context = new WebApiCrudContext();
     context.Categories.Add(category);
     context.SaveChanges();
     return(Created("", category));
 }
示例#2
0
        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());
        }
示例#3
0
        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());
        }