DeliveryAdminWindow: Cache modifiers
All checks were successful
Test / Run tests (push) Successful in 2m3s

This commit is contained in:
2026-04-05 23:19:13 +02:00
parent ae4e5be820
commit e25f4bb1bf
4 changed files with 14 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ namespace Elwig.Windows {
private readonly Button[] WeighingButtons;
private List<WineQualLevel> WineQualityLevels = [];
private List<Modifier> Modifiers = [];
public DeliveryAdminWindow(bool receipt = false) {
InitializeComponent();
@@ -506,7 +507,7 @@ namespace Elwig.Windows {
}
var attributes = await ctx.FetchWineAttributes(!IsCreating).ToListAsync();
var modifiers = await ctx.FetchModifiers(year, !IsCreating).ToListAsync();
Modifiers = await ctx.FetchModifiers(null).ToListAsync();
var font = new FontFamily("Segoe MDL2 Assets");
Menu_BulkAction_SetAttribute.Items.Clear();
@@ -526,7 +527,7 @@ namespace Elwig.Windows {
Menu_BulkAction_AddModifier.Items.Clear();
Menu_BulkAction_RemoveModifier.Items.Clear();
foreach (var mod in modifiers) {
foreach (var mod in Modifiers.Where(m => m.Year == (ViewModel.SelectedDelivery?.Year ?? 0) && (m.IsActive || !IsCreating))) {
var i1 = new MenuItem {
Header = mod.Name,
};
@@ -552,7 +553,7 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(CultivationInput, cultList, null, ControlUtils.RenewSourceDefault.First);
WineQualityLevels = await ctx.FetchWineQualityLevels().ToListAsync();
ControlUtils.RenewItemsSource(WineQualityLevelInput, WineQualityLevels);
ControlUtils.RenewItemsSource(ModifiersInput, modifiers);
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.Where(m => m.Year == year && (m.IsActive || !IsCreating)).ToList());
var origins = await ctx.WineOrigins.ToListAsync();
origins.ForEach(o => { origins.FirstOrDefault(p => p.HkId == o.ParentHkId)?.Children.Add(o); });
origins = [.. origins.OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId)];
@@ -579,12 +580,11 @@ namespace Elwig.Windows {
}
private async Task RefreshDeliveryParts() {
using var ctx = new AppDbContext();
if (DeliveryList.SelectedItem is Delivery d) {
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(d.Year, !IsCreating).ToListAsync());
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.Where(m => m.Year == d.Year && (m.IsActive || !IsCreating)).ToList());
ControlUtils.RenewItemsSource(DeliveryPartList, d.Parts, DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
} else {
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(ViewModel.FilterSeason, !IsCreating).ToListAsync());
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.Where(m => m.Year == ViewModel.FilterSeason && (m.IsActive || !IsCreating)).ToList());
DeliveryPartList.ItemsSource = null;
}
}
@@ -913,7 +913,7 @@ namespace Elwig.Windows {
var attrList = await ctx.FetchWineAttributes(false).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(ViewModel.FilterSeason, false).ToListAsync());
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.Where(m => m.Year == ViewModel.FilterSeason && m.IsActive).ToList());
ControlUtils.RenewItemsSource(MemberInput, await ctx.FetchMembers(includeNotActive: !ViewModel.IsReceipt, includeContactInfo: true).ToListAsync());
IsCreating = true;
DeliveryList.IsEnabled = false;