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.
parent
d3472f37a3
commit
fc762456a4
|
|
@ -299,10 +299,27 @@ public partial class MealSchedulesViewModel : ObservableObject
|
||||||
|
|
||||||
private void ApplyFilter()
|
private void ApplyFilter()
|
||||||
{
|
{
|
||||||
var site = string.IsNullOrWhiteSpace(_currentSiteId) ? "01" : _currentSiteId;
|
// 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 : "
|
||||||
|
|
||||||
|
// 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
|
var filtered = _allSchedules
|
||||||
.Where(s => string.Equals(s.LocationSiteId?.Trim(), site, StringComparison.OrdinalIgnoreCase))
|
.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();
|
.ToList();
|
||||||
|
|
||||||
|
// Update the UI with the filtered results.
|
||||||
Schedules = new ObservableCollection<MealSchedule>(filtered);
|
Schedules = new ObservableCollection<MealSchedule>(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue