From d031b0b998b1ed6d5b93ab418183f5af4a213f79 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:53:57 -0700 Subject: [PATCH] Update InventoryController.cs --- .../Controllers/InventoryController.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs index 4f8210e..40baa59 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs @@ -105,14 +105,16 @@ public class InventoryController : Controller { // Inventory/Delete => Décrémenter un produit. [EnableCors("_myAllowSpecificOrigins")] [HttpDelete(Name = "Inventory")] - public void Delete(int? id) { + public ActionResult Delete(int? id) { + int rid = 0; if (!id.HasValue) { _logger.LogError(8, "Delete sans Id."); - return; + return BadRequest(); } try { Product prod = _context.Products.First(x => x.Id == id); + rid = prod.Id; if (prod.Quantity > 0) { prod.Quantity = prod.Quantity - 1; if (prod.Quantity == 0) @@ -122,13 +124,15 @@ public class InventoryController : Controller { } else { _logger.LogError(8, "Vente de produit pas en stock."); - return; + return BadRequest(); } _context.Products.Update(prod); _context.SaveChanges(); } catch (Exception e) { _logger.LogError(8, e.Message); + return BadRequest(); } + return rid; } }