using System; using System.Collections.Generic; using System.Linq; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using kuzminIVProjectWorkOnDemo.Models; using ReactiveUI; namespace kuzminIVProjectWorkOnDemo.ViewModels { public class ServiceListPageViewModel : ReactiveObject { KuzmintestprojContext db; List services; public ServiceListPageViewModel(KuzmintestprojContext db) { this.db = db; this.services = db.Sevices.ToList(); } public List Services { get => services; set => this.RaiseAndSetIfChanged(ref services, value); } int indexsort; int costindex; string search; string textcount; public int IndexSort { get => indexsort; set { indexsort = value; filter(); } } public int Costindex { get => costindex; set { costindex = value; filter(); } } public string Search { get => search; set { search = value; filter(); } } public string Textcount { get => textcount; set => this.RaiseAndSetIfChanged(ref textcount, value); } public bool AdminBool { get => Models.Sevice.IsVisibleAdmin; } void filter() { Services = db.Sevices.ToList(); switch (Costindex) { case 1: Services = Services.Where(x => x.Discount >= 0 && x.Discount < 0.05).ToList(); break; case 2: Services = Services.Where(x => x.Discount >= 0.05 && x.Discount < 0.15).ToList(); break; case 3: Services = Services.Where(x => x.Discount >= 0.15 && x.Discount < 0.3).ToList(); break; case 4: Services = Services.Where(x => x.Discount >= 0.3 && x.Discount < 0.7).ToList(); break; case 5: Services = Services.Where(x => x.Discount >= 0.7 && x.Discount < 1).ToList(); break; } if (!string.IsNullOrWhiteSpace(Search)) { Services = Services.Where(x => x.Title.ToLower().Contains(Search.ToLower())).ToList(); } switch (IndexSort) { case 0: Services = Services.OrderBy(x => x.CostWithDiscount).ToList(); break; case 1: Services = Services.OrderByDescending(x => x.CostWithDiscount).ToList(); break; } Textcount = Services.Count.ToString() + " θη " + db.Sevices.ToList().Count.ToString(); } public void pressButton() { ClientZapisWindow clientZapisWindow = new ClientZapisWindow { DataContext = new ClientZapisWindowViewModel() }; var mainWindow = Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ? desktop.MainWindow : null; clientZapisWindow.ShowDialog(mainWindow); //clientZapisWindow.Show(); } } }