public IActionResult AddCategory(Category category) { using var context = new WebApiCrudContext(); context.Categories.Add(category); context.SaveChanges(); return(Created("", category)); }
public IActionResult Get(int id) { using var context = new WebApiCrudContext(); var category = context.Categories.Find(id); if (category == null) { return(NotFound()); } return(Ok(category)); }
public IActionResult GetWithBlogsById(int id) { using var context = new WebApiCrudContext(); var categoryIdFind = context.Categories.Find(id); if (categoryIdFind == null) { return(NotFound()); } var categorywithblogs = context.Categories.Where(x => x.Id == id).Include(x => x.Blogs).ToList(); return(Ok(categorywithblogs)); }
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()); }
public IActionResult Get() { using var context = new WebApiCrudContext(); return(Ok(context.Categories.ToList())); }