Working filter
This commit is contained in:
@@ -47,19 +47,52 @@ public partial class Home : ComponentBase
|
||||
{
|
||||
var data = ProductsCollection.AsEnumerable();
|
||||
|
||||
// Category filtering restricts rendering solely when checking the open catalog
|
||||
// 1. Category Filtering
|
||||
if (ActiveCategory != "All" && !AuthorId.HasValue)
|
||||
{
|
||||
data = data.Where(p => ProductPrimaryCategoryCache.ContainsKey(p.Id) &&
|
||||
ProductPrimaryCategoryCache[p.Id] == ActiveCategory);
|
||||
}
|
||||
|
||||
// Text matching is completely restricted from evaluating author metadata properties
|
||||
// 2. Text Search Query Matching
|
||||
if (!string.IsNullOrWhiteSpace(SharedSearchQuery))
|
||||
{
|
||||
var q = SharedSearchQuery.Trim();
|
||||
|
||||
data = data.Where(p => (p.Name ?? "").Contains(q, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
// 3. FIX: Price Tier Constraint Selection Layout
|
||||
if (ActivePriceFilter != "all")
|
||||
{
|
||||
data = data.Where(p =>
|
||||
{
|
||||
var price = ProductPriceCache.TryGetValue(p.Id, out var amt) ? amt : 0m;
|
||||
return ActivePriceFilter switch
|
||||
{
|
||||
"under-500" => price < 500m,
|
||||
"500-1000" => price >= 500m && price <= 1000m,
|
||||
"over-1000" => price > 1000m,
|
||||
_ => true
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// 4. FIX: New Acquisition Flag Status Check
|
||||
if (OnlyShowNew)
|
||||
{
|
||||
// Utilizing your mapping configuration: book.Enabled defines new arrival status
|
||||
data = data.Where(p => p.Enabled);
|
||||
}
|
||||
|
||||
// 5. FIX: Collection Sorting Pipeline Extensions
|
||||
data = SelectedSortOption switch
|
||||
{
|
||||
"price-low" => data.OrderBy(p => ProductPriceCache.TryGetValue(p.Id, out var amt) ? amt : 0m),
|
||||
"price-high" => data.OrderByDescending(p => ProductPriceCache.TryGetValue(p.Id, out var amt) ? amt : 0m),
|
||||
"title-asc" => data.OrderBy(p => p.Name ?? string.Empty, StringComparer.OrdinalIgnoreCase),
|
||||
"default" or _ => data // Fallback to raw catalog chronological order sequence
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user