From 47eb4525419f1e0a48e38886c318c27992694cb4 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Tue, 18 Oct 2022 07:43:52 -0700 Subject: [PATCH] Update InventoryController.cs --- .../Controllers/InventoryController.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs index 09094ec..a1744e7 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs @@ -59,10 +59,10 @@ public class InventoryController : Controller { switch (order) { case "Price": - ret = ret.OrderBy(x => x.Price); + ret = ret.OrderBy(x => x.Status == Product.States.Promotion? x.PromoPrice: x.Price); break; case "PriceDesc": - ret = ret.OrderByDescending(x => x.Price); + ret = ret.OrderByDescending(x => x.Status == Product.States.Promotion ? x.PromoPrice : x.Price); break; case "Title": ret = ret.OrderBy(x => x.Title); @@ -79,21 +79,20 @@ public class InventoryController : Controller { default: break; } - List lst = ret.ToList(); + List lst = new(); + bool yup = false; + int add = 0; if (lastId.HasValue) - foreach (Product prod in new List(lst)) { - lst.Remove(prod); + foreach (Product prod in new List(ret.ToList())) { + if (yup && add < AMOUNT) { + lst.Add(prod); + add++; + } 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); }