react-version #1

Merged
memartel merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
Showing only changes of commit d031b0b998 - Show all commits

View File

@@ -105,14 +105,16 @@ public class InventoryController : Controller {
// Inventory/Delete => Décrémenter un produit. // Inventory/Delete => Décrémenter un produit.
[EnableCors("_myAllowSpecificOrigins")] [EnableCors("_myAllowSpecificOrigins")]
[HttpDelete(Name = "Inventory")] [HttpDelete(Name = "Inventory")]
public void Delete(int? id) { public ActionResult<int> Delete(int? id) {
int rid = 0;
if (!id.HasValue) { if (!id.HasValue) {
_logger.LogError(8, "Delete sans Id."); _logger.LogError(8, "Delete sans Id.");
return; return BadRequest();
} }
try { try {
Product prod = _context.Products.First(x => x.Id == id); Product prod = _context.Products.First(x => x.Id == id);
rid = prod.Id;
if (prod.Quantity > 0) { if (prod.Quantity > 0) {
prod.Quantity = prod.Quantity - 1; prod.Quantity = prod.Quantity - 1;
if (prod.Quantity == 0) if (prod.Quantity == 0)
@@ -122,13 +124,15 @@ public class InventoryController : Controller {
} }
else { else {
_logger.LogError(8, "Vente de produit pas en stock."); _logger.LogError(8, "Vente de produit pas en stock.");
return; return BadRequest();
} }
_context.Products.Update(prod); _context.Products.Update(prod);
_context.SaveChanges(); _context.SaveChanges();
} catch (Exception e) { } catch (Exception e) {
_logger.LogError(8, e.Message); _logger.LogError(8, e.Message);
return BadRequest();
} }
return rid;
} }
} }