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