Skip to content

Commit 68ae6d9

Browse files
committed
Enhance category handling in Category.cshtml.cs to validate and redirect based on category casing; update category header styles in Category.cshtml for improved visibility
1 parent 54b5c9c commit 68ae6d9

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

Web/Pages/Index.cshtml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@
6363
<!-- Categories Section -->
6464
<div class="container-fluid py-5 mb-5">
6565
<div class="container">
66-
<h2 class="fw-bold mb-4"><i class="bi bi-folder2-open"></i> Explore Categories</h2>
66+
<h2 class="fw-bold mb-4"><i class="bi bi-folder2-open text-primary"></i> Explore Categories</h2>
6767
<div class="row g-4">
6868
@foreach (var category in Model.Categories)
6969
{
70-
<div class="col-lg-3 col-md-4 col-sm-6">
71-
<a asp-page="/Tips/Category" asp-route-category="@category.ToLowerInvariant()"
70+
<div class="col-lg-3 col-md-4 col-sm-6"> <a asp-page="/Tips/Category" asp-route-category="@category.ToLowerInvariant()"
7271
class="card text-decoration-none text-dark hover-card h-100">
7372
<div class="card-body d-flex align-items-center gap-3">
74-
<i class="bi bi-folder2 fs-3"></i>
73+
<i class="bi bi-folder2-fill fs-3 text-primary"></i>
7574
<h5 class="card-title mb-0">@category</h5>
7675
</div>
7776
</a>

Web/Pages/Tips/Category.cshtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
<div class="row">
3838
<!-- Category Filter Sidebar -->
39-
<div class="col-lg-3 col-md-4 mb-4"> <div class="card shadow-sm">
39+
<div class="col-lg-3 col-md-4 mb-4">
40+
<div class="card shadow-sm">
4041
<div class="card-header category-filter-header">
4142
<h5 class="card-title mb-0">
4243
<i class="bi bi-grid-3x3-gap"></i> Browse Categories
@@ -47,17 +48,17 @@
4748
{
4849
<a asp-page="/Tips/Category" asp-route-category="@cat"
4950
class="list-group-item list-group-item-action border-0 @(cat == Model.Category ? "active" : "")">
50-
@cat
51-
@if (cat == Model.Category)
51+
@cat @if (cat == Model.Category)
5252
{
53-
<span class="badge bg-light text-primary ms-2">@Model.ViewModel.TotalCount</span>
53+
<span class="badge bg-light text-primary ms-2 border border-primary">@Model.ViewModel.TotalCount</span>
5454
}
5555
</a>
5656
}
5757
</div>
5858
</div>
5959

60-
<!-- Additional Filters --> <div class="card shadow-sm mt-3">
60+
<!-- Additional Filters -->
61+
<div class="card shadow-sm mt-3">
6162
<div class="card-header category-filter-header">
6263
<h6 class="card-title mb-0">
6364
<i class="bi bi-funnel"></i> Refine Results

Web/Pages/Tips/Category.cshtml.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ public async Task<IActionResult> OnGetAsync()
3131

3232
try
3333
{
34+
// Get filter options first to validate category
35+
var categories = await _contentService.GetCategoriesAsync();
36+
var tags = await _contentService.GetTagsAsync();
37+
38+
// Find the matching category with correct casing
39+
var matchingCategory = categories.FirstOrDefault(c =>
40+
c.Equals(Category, StringComparison.OrdinalIgnoreCase));
41+
42+
// If category doesn't exist, redirect to index
43+
if (matchingCategory == null)
44+
{
45+
return RedirectToPage("/Tips/Index");
46+
}
47+
48+
// If category exists but with different casing, redirect to correct casing
49+
if (matchingCategory != Category)
50+
{
51+
return RedirectToPage("/Tips/Category", new { category = matchingCategory });
52+
}
53+
3454
var request = new TipSearchRequest
3555
{
3656
Category = Category,
@@ -41,10 +61,6 @@ public async Task<IActionResult> OnGetAsync()
4161
var tips = await _contentService.SearchTipsAsync(request);
4262
var totalCount = tips.Count;
4363

44-
// Get filter options
45-
var categories = await _contentService.GetCategoriesAsync();
46-
var tags = await _contentService.GetTagsAsync();
47-
4864
ViewModel = new TipListViewModel
4965
{
5066
Tips = tips,

0 commit comments

Comments
 (0)