Corrections dans l'API

This commit is contained in:
MarcEricMartel 2022-10-16 07:39:10 -07:00
parent 0b5bb86291
commit db4fc250b9

View File

@ -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<Product> 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();
}