Correction
This commit is contained in:
@@ -132,37 +132,37 @@ public class InventoryController : Controller {
|
||||
}
|
||||
}
|
||||
// Inventory/Delete => Décrémenter un produit. Va aller chercher directement dans la BD.
|
||||
[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Inventory"), AllowAnonymous]
|
||||
public ActionResult<int> Delete(int? id) {
|
||||
int rid = 0;
|
||||
if (!id.HasValue) {
|
||||
_logger.LogError(8, "Tentative de vente sans Id.");
|
||||
return BadRequest();
|
||||
}
|
||||
try {
|
||||
ProductModel prod = _context.Products.First(x => x.Id == id);
|
||||
rid = prod.Id;
|
||||
if (prod.Quantity > 0) {
|
||||
prod.Quantity = prod.Quantity - 1;
|
||||
prod.Sales = prod.Sales + 1;
|
||||
prod.LastSale = DateTime.Now;
|
||||
if (prod.Quantity == 0)
|
||||
prod.Status = prod.Status == ProductModel.States.Clearance ?
|
||||
ProductModel.States.Discontinued :
|
||||
ProductModel.States.BackOrder;
|
||||
} else {
|
||||
_logger.LogError(8, $"Vente de produit pas en stock. Id Produit: {prod.Id}");
|
||||
return BadRequest();
|
||||
}
|
||||
_context.Products.Update(prod);
|
||||
_context.SaveChanges();
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
return BadRequest();
|
||||
}
|
||||
_cache.askForRefresh();
|
||||
return rid;
|
||||
}
|
||||
//[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Inventory"), AllowAnonymous]
|
||||
//public ActionResult<int> Delete(int? id) {
|
||||
// int rid = 0;
|
||||
// if (!id.HasValue) {
|
||||
// _logger.LogError(8, "Tentative de vente sans Id.");
|
||||
// return BadRequest();
|
||||
// }
|
||||
// try {
|
||||
// ProductModel prod = _context.Products.First(x => x.Id == id);
|
||||
// rid = prod.Id;
|
||||
// if (prod.Quantity > 0) {
|
||||
// prod.Quantity = prod.Quantity - 1;
|
||||
// prod.Sales = prod.Sales + 1;
|
||||
// prod.LastSale = DateTime.Now;
|
||||
// if (prod.Quantity == 0)
|
||||
// prod.Status = prod.Status == ProductModel.States.Clearance ?
|
||||
// ProductModel.States.Discontinued :
|
||||
// ProductModel.States.BackOrder;
|
||||
// } else {
|
||||
// _logger.LogError(8, $"Vente de produit pas en stock. Id Produit: {prod.Id}");
|
||||
// return BadRequest();
|
||||
// }
|
||||
// _context.Products.Update(prod);
|
||||
// _context.SaveChanges();
|
||||
// } catch (Exception e) {
|
||||
// _logger.LogError(8, e.Message);
|
||||
// return BadRequest();
|
||||
// }
|
||||
// _cache.askForRefresh();
|
||||
// return rid;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user