public IActionResult DeleteProductFromSupermarket(int supermarketId, int productId) { // check supermarket exists if (!_supermarketRepository.SupermarketExists(supermarketId)) { return(NotFound()); } // get targeted stock var productFromSupermarketFromRepo = _supermarketRepository.GetStockByProductAndSupermarket(supermarketId, productId); // check stock not null if (productFromSupermarketFromRepo == null) { return(NotFound()); } // delete and save _supermarketRepository.DeleteSupermarketStock(productFromSupermarketFromRepo); if (!_supermarketRepository.Save()) { throw new Exception($"Deleting product {productId} from supermarket {supermarketId} failed on save."); } return(NoContent()); }
public IActionResult DeleteSupermarketStock(int id) { // get stock for deletion var supermarketStockFromRepo = _supermarketRepository.GetStockById(id); // check stock exists if (supermarketStockFromRepo == null) { return(NotFound()); } // delete and save _supermarketRepository.DeleteSupermarketStock(supermarketStockFromRepo); if (!_supermarketRepository.Save()) { throw new Exception($"Deleting stock {id} failed on save."); } // return 204 on success return(NoContent()); }