From fc762456a43a69f918f7965df7ec22ec09fae0dc Mon Sep 17 00:00:00 2001 From: "mustafa.ahmed" Date: Wed, 18 Mar 2026 13:38:09 +0500 Subject: [PATCH] Implemented dynamic site filter logic for meal schedules view. Updated the site selection filter to ensure proper normalization of site IDs from the config and database, allowing accurate display of meal schedules based on the selected site. --- ViewModels/MealSchedulesViewModel.cs | 33 +++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/ViewModels/MealSchedulesViewModel.cs b/ViewModels/MealSchedulesViewModel.cs index e867893..e3b6692 100644 --- a/ViewModels/MealSchedulesViewModel.cs +++ b/ViewModels/MealSchedulesViewModel.cs @@ -296,15 +296,32 @@ public partial class MealSchedulesViewModel : ObservableObject { ApplyFilter(); } + + private void ApplyFilter() +{ + // Remove "SITE : " from the config SiteId and normalize it (pad with leading zeros if necessary) + var site = string.IsNullOrWhiteSpace(_currentSiteId) + ? "01" + : _currentSiteId.Replace("SITE : ", "").PadLeft(2, '0'); // Normalize to two digits if empty or contains "SITE : " - private void ApplyFilter() - { - var site = string.IsNullOrWhiteSpace(_currentSiteId) ? "01" : _currentSiteId; - var filtered = _allSchedules - .Where(s => string.Equals(s.LocationSiteId?.Trim(), site, StringComparison.OrdinalIgnoreCase)) - .ToList(); - Schedules = new ObservableCollection(filtered); - } + // Log the site ID we're filtering by (for debugging purposes). + Console.WriteLine($"Filtering for site: {site}"); + + // Filter the meal schedules by the normalized site ID. + var filtered = _allSchedules + .Where(s => + { + // Normalize the LocationSiteId from the schedule to ensure consistency. + var normalizedLocationSiteId = s.LocationSiteId?.Trim().PadLeft(2, '0') ?? "00"; + Console.WriteLine($"Checking: {normalizedLocationSiteId} vs {site}"); + + return string.Equals(normalizedLocationSiteId, site, StringComparison.OrdinalIgnoreCase); + }) + .ToList(); + + // Update the UI with the filtered results. + Schedules = new ObservableCollection(filtered); +} private async Task LoadSchedulesAsync() {