[#43] BaseDataWindow: Do not use Context from ContextWindow any more

This commit is contained in:
2024-03-18 10:28:35 +01:00
parent 5715c41a2e
commit 729d2fd76c
7 changed files with 154 additions and 122 deletions

View File

@ -12,27 +12,27 @@ namespace Elwig.Windows {
private bool _seasonChanged = false;
private bool _seasonUpdate = false;
private void SeasonsInitEditing() {
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
private async Task SeasonsInitEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year);
SeasonList_SelectionChanged(null, null);
}
private void SeasonsFinishEditing() {
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
private async Task SeasonsFinishEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).Include(s => s.Modifiers).ToListAsync(), s => (s as Season)?.Year);
_seasonChanged = false;
}
private async Task SeasonsSave() {
private async Task SeasonsSave(AppDbContext ctx) {
if (!_seasonChanged || SeasonList.SelectedItem is not Season s)
return;
Context.Update(s);
await Context.SaveChangesAsync();
ctx.Update(s);
await ctx.SaveChangesAsync();
}
private async void SeasonList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
private void SeasonList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
_seasonUpdate = true;
if (SeasonList.SelectedItem is Season s) {
SeasonModifierList.ItemsSource = await Context.Modifiers.Where(m => m.Year == s.Year).OrderBy(m => m.Ordering).ToListAsync();
SeasonModifierList.ItemsSource = s.Modifiers.OrderBy(m => m.Ordering).ToList();
SeasonMaxKgPerHaInput.Text = s.MaxKgPerHa.ToString();
SeasonVatNormalInput.Text = (s.VatNormal * 100).ToString();
SeasonVatFlatrateInput.Text = (s.VatFlatrate * 100).ToString();