diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs index 6a90399..35b8e06 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs @@ -18,8 +18,6 @@ public class InventoryController : Controller { [HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de 5 (pour du loading en scrollant) public IEnumerable Get(int? lastId, string order, string filter) { - if (!lastId.HasValue) - lastId = 1; var ret = _context.Products.AsQueryable(); switch (filter) { @@ -75,9 +73,18 @@ public class InventoryController : Controller { .Where(x => x.Id < lastId && x.Id > lastId - 5); break; default: - ret = ret.Where(x => x.Id > lastId && x.Id < lastId + 5); + break; } + if (order.Contains("Desc")) { + if (!lastId.HasValue) + lastId = _context.Products.Max(x => x.Id); + ret = ret.Where(x => x.Id < lastId && x.Id > lastId - 5) + } else { + if (!lastId.HasValue) + lastId = 1; + ret = ret.Where(x => x.Id > lastId && x.Id < lastId + 5); + } return ret.ToList(); }