Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Carneiro committed Feb 6, 2025
2 parents bffb42d + 7bb0853 commit efcd6a4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Areas/Admin/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IActionResult Index(string filterText = "", string sortOrder = "")
return Problem("Entity set 'ApplicationDbContext.Product' is null.");
}

ViewBag.SortParmName = string.IsNullOrEmpty(sortOrder) ? "-Name" : "";
ViewBag.SortParmName = sortOrder == "Name" ? "-Name" : "Name";
ViewBag.SortParmVolume = sortOrder == "Volume" ? "-Volume" : "Volume";
ViewBag.SortParmWineVintage = sortOrder == "WineVintage" ? "-WineVintage" : "WineVintage";
ViewBag.SortParmWineType = sortOrder == "WineType" ? "-WineType" : "WineType";
Expand All @@ -45,9 +45,9 @@ public IActionResult Index(string filterText = "", string sortOrder = "")

var query = _context.Product
.AsNoTracking()
.OrderBy(i => i.Name)
.OrderByDescending(i => i.WineInformation.Vintage)
.ThenBy(i => i.Name)
.ThenBy(i => i.Volume)
.ThenBy(i => i.WineInformation.Vintage)
.AsQueryable()
.AsEnumerable();

Expand All @@ -74,7 +74,10 @@ public IActionResult Index(string filterText = "", string sortOrder = "")

switch (sortOrder)
{
default: // "Name":
default:
query = query.OrderByDescending(p => p.WineInformation.Vintage).ThenBy(p => p.Name).ThenBy(p => p.Volume);
break;
case "Name":
query = query.OrderBy(p => p.Name).ThenBy(p => p.Volume).ThenBy(p => p.WineInformation.Vintage);
break;
case "-Name":
Expand All @@ -87,10 +90,10 @@ public IActionResult Index(string filterText = "", string sortOrder = "")
query = query.OrderByDescending(p => p.Volume).ThenBy(p => p.Name).ThenBy(p => p.Volume).ThenBy(p => p.WineInformation.Vintage);
break;
case "WineVintage":
query = query.OrderBy(p => p.WineInformation.Vintage).ThenBy(p => p.Name).ThenBy(p => p.Volume).ThenBy(p => p.WineInformation.Vintage);
query = query.OrderBy(p => p.WineInformation.Vintage).ThenBy(p => p.Name).ThenBy(p => p.Volume);
break;
case "-WineVintage":
query = query.OrderByDescending(p => p.WineInformation.Vintage).ThenBy(p => p.Name).ThenBy(p => p.Volume).ThenBy(p => p.WineInformation.Vintage);
query = query.OrderByDescending(p => p.WineInformation.Vintage).ThenBy(p => p.Name).ThenBy(p => p.Volume);
break;
case "WineType":
query = query.OrderBy(p => p.WineInformation.Type).ThenBy(p => p.Name).ThenBy(p => p.Volume).ThenBy(p => p.WineInformation.Vintage);
Expand Down

0 comments on commit efcd6a4

Please sign in to comment.