public async Task <IActionResult> PutCategory(int id, Category category) { if (id != category.Id) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryCheck(id)) { return(NotFound()); } else { _logger.LogError("PUT Category Failed to save changes"); throw; } } return(NoContent()); }
public async Task <ActionResult <Supplier> > PostSupplier(Supplier supplier) { try { _context.Supplier.Add(supplier); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSupplier", new { id = supplier.Id }, supplier)); } catch (Exception exception) { _logger.LogError(exception.Message); throw; } }
public async Task <ActionResult <Product> > PostProduct(Product product) { try { _context.Product.Add(product); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProduct", new { id = product.Id }, product)); } catch (Exception exception) { _logger.LogError(exception.Message); throw; } }