public ActionResult AddProduct([FromBody] Product product) { _context.Products.Add(product); _context.SaveChanges(); return(Created($"/api/product/{product.Id}", product)); }
public ActionResult AddCategory([FromBody] Category category) { _context.Categories.Add(category); _context.SaveChanges(); return(Created($"/api/category/{category.Id}", category)); }
public ActionResult AddProductToCategory([FromBody] ProductCategory productCategory) { var category = _context.Categories .Include(c => c.ProductCategories) .FirstOrDefault(c => c.Id == productCategory.CategoryId); var product = _context.Products.FirstOrDefault(p => p.Id == productCategory.ProductId); if (category == null) { return(NotFound()); } if (product == null) { return(NotFound()); } category.ProductCategories.Add(productCategory); _context.SaveChanges(); return(Created($"/api/productcategory/{productCategory.CategoryId}-{productCategory.ProductId}", productCategory)); }