Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version

This commit is contained in:
Victor Turgeon 2022-10-18 07:44:32 -04:00
commit 4230184d8c

View File

@ -59,10 +59,10 @@ public class InventoryController : Controller {
switch (order) { switch (order) {
case "Price": case "Price":
ret = ret.OrderBy(x => x.Price); ret = ret.OrderBy(x => x.Status == Product.States.Promotion? x.PromoPrice: x.Price);
break; break;
case "PriceDesc": case "PriceDesc":
ret = ret.OrderByDescending(x => x.Price); ret = ret.OrderByDescending(x => x.Status == Product.States.Promotion ? x.PromoPrice : x.Price);
break; break;
case "Title": case "Title":
ret = ret.OrderBy(x => x.Title); ret = ret.OrderBy(x => x.Title);
@ -79,20 +79,19 @@ public class InventoryController : Controller {
default: break; default: break;
} }
List<Product> lst = ret.ToList(); List<Product> lst = new();
bool yup = false;
int add = 0;
if (lastId.HasValue) if (lastId.HasValue)
foreach (Product prod in new List<Product>(lst)) { foreach (Product prod in new List<Product>(ret.ToList())) {
lst.Remove(prod); if (yup && add < AMOUNT) {
lst.Add(prod);
add++;
}
if (prod.Id == lastId) if (prod.Id == lastId)
break; yup = true;
} }
//if (order is not null && order.Contains("Desc")) {
// if (!lastId.HasValue)
// lastId = _context.Products.Max(x => x.Id) + 1;
//} else
// if (!lastId.HasValue)
// lastId = _context.Products.Min(x => x.Id) - 1;
return lst.Take(AMOUNT); return lst.Take(AMOUNT);
} }