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.

pull/2/head
SYED MUSTUFA AHMED NAQVI 2026-03-18 13:38:09 +05:00
parent d3472f37a3
commit fc762456a4
1 changed files with 25 additions and 8 deletions

View File

@ -296,15 +296,32 @@ public partial class MealSchedulesViewModel : ObservableObject
{ {
ApplyFilter(); 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() // Log the site ID we're filtering by (for debugging purposes).
{ Console.WriteLine($"Filtering for site: {site}");
var site = string.IsNullOrWhiteSpace(_currentSiteId) ? "01" : _currentSiteId;
var filtered = _allSchedules // Filter the meal schedules by the normalized site ID.
.Where(s => string.Equals(s.LocationSiteId?.Trim(), site, StringComparison.OrdinalIgnoreCase)) var filtered = _allSchedules
.ToList(); .Where(s =>
Schedules = new ObservableCollection<MealSchedule>(filtered); {
} // 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<MealSchedule>(filtered);
}
private async Task LoadSchedulesAsync() private async Task LoadSchedulesAsync()
{ {