This commit is contained in:
MarcEricMartel 2022-10-16 07:33:16 -07:00
parent 355e1761b4
commit 0b5bb86291
2 changed files with 63 additions and 5 deletions

View File

@ -17,12 +17,71 @@ 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) {
public IEnumerable<Product> Get(int? lastId, string order, string filter) {
if (!lastId.HasValue)
lastId = 1;
return _context.Products.Where(x => x.Id >= lastId && x.Id < lastId + 5).ToList();
var ret = _context.Products.AsQueryable();
switch (filter) {
case "PriceUnder20":
ret = ret.Where(x => x.Price < 20);
break;
case "Price20to49":
ret = ret.Where(x => x.Price >= 20 && x.Price < 50);
break;
case "Price50to99":
ret = ret.Where(x => x.Price >= 50 && x.Price < 100);
break;
case "PriceOver100":
ret = ret.Where(x => x.Price >= 100);
break;
case "isAvailable":
ret = ret.Where(x => x.Quantity > 0);
break;
case "isBackOrder":
ret = ret.Where(x => x.Quantity == 0 || !x.isDiscontinued);
break; ;
case "isClearance":
ret = ret.Where(x => x.Quantity > 0 && x.isDiscontinued);
break;
case "isDiscontinued":
ret = ret.Where(x => x.Quantity == 0 && x.isDiscontinued);
break;
}
switch (order) {
case "Price":
ret = ret.OrderBy(x => x.Price)
.Where(x => x.Id > lastId && x.Id < lastId + 5);
break;
case "PriceDesc":
ret = ret.OrderByDescending(x => x.Price)
.Where(x => x.Id < lastId && x.Id > lastId - 5);
break;
case "Title":
ret = ret.OrderBy(x => x.Title)
.Where(x => x.Id > lastId && x.Id < lastId + 5);
break;
case "TitleDesc":
ret = ret.OrderByDescending(x => x.Title)
.Where(x => x.Id < lastId && x.Id > lastId - 5);
break;
case "Category":
ret = ret.OrderBy(x => x.Category)
.Where(x => x.Id > lastId && x.Id < lastId + 5);
break;
case "CategoryDesc":
ret = ret.OrderByDescending(x => x.Category)
.Where(x => x.Id < lastId && x.Id > lastId - 5);
break;
default:
ret = ret.Where(x => x.Id > lastId && x.Id < lastId + 5);
break;
}
return ret.ToList();
}
// Inventory/Delete => Décrémenter un produit.
[HttpDelete(Name = "Inventory")]
public void Delete(int? id) {
if (!id.HasValue) {

View File

@ -17,7 +17,7 @@ public class SearchController : Controller {
}
[HttpPost(Name = "Search")]
public IEnumerable<Product> Post(string query, bool preview) {
public IEnumerable<Product> Post(string query) {
HashSet<Product> products = new();
query = query.Trim();
@ -29,7 +29,6 @@ public class SearchController : Controller {
} catch (Exception e) {
_logger.LogError(8, e.Message);
}
return products;
}