using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Microsoft.EntityFrameworkCore; using System.Linq; using tiron_demo.Context; using tiron_demo.Models; namespace tiron_demo; public partial class History : Window { private short _previousWindow; public History() { InitializeComponent(); _previousWindow = 0; HistoryBox.ItemsSource = Helper.context.PartnerProducts.Include(x => x.PartnerNavigation).Include(x => x.ProductNavigation); } public History(Window previousWindow, int partnerId, int productId) { InitializeComponent(); if (previousWindow is ProductsWindow) { _previousWindow = 1; } else if (previousWindow is PartnersWindow) { _previousWindow = 2; } if (productId != 0) { var source = Helper.context.PartnerProducts.Where(x => x.Product == productId); if (partnerId != 0) { source = source.Where(x => x.Partner == partnerId); } HistoryBox.ItemsSource = source.Include(x => x.PartnerNavigation).Include(x => x.ProductNavigation); } else if (partnerId != 0) { HistoryBox.ItemsSource = Helper.context.PartnerProducts.Where(x => x.Partner == partnerId).Include(x => x.PartnerNavigation).Include(x => x.ProductNavigation); } else { HistoryBox.ItemsSource = Helper.context.PartnerProducts.Include(x => x.PartnerNavigation).Include(x => x.ProductNavigation); } } private void Button_Click_Back(object? sender, RoutedEventArgs args) { if (_previousWindow == 0) { MainWindow mainWindow = new MainWindow(); mainWindow.Show(); } else if (_previousWindow == 1) { ProductsWindow productsWindow = new ProductsWindow(); productsWindow.Show(); } else if (_previousWindow == 2) { PartnersWindow partnersWindow = new PartnersWindow(); partnersWindow.Show(); } Close(); } }