using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media.Imaging; using Avalonia.Platform.Storage; using AvaloniaHomeTry.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; using ReactiveUI; using Tmds.DBus.Protocol; namespace AvaloniaHomeTry.ViewModels { public partial class AdminPageViewModel : ViewModelBase { UsersTable myUsers = new UsersTable(); List genderList; List usersTables; List usersTables0; Gender filterGender; string find; public List GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); } public List UsersTables { get => usersTables; set => this.RaiseAndSetIfChanged(ref usersTables, value); } public List UsersTables0 { get => usersTables0; set => this.RaiseAndSetIfChanged(ref usersTables0, value); } public Gender FilterGender { get => filterGender; set { filterGender = value; AllFilters(); } } public string Find { get => find; set { find = value; AllFilters(); } } public AdminPageViewModel() { usersTables = db.UsersTable.ToList(); genderList = db.Genders.ToList(); genderList.Add(new Gender() { Id = 0, GenderName = "Ñáðîñèòü ôèëüòðû"}); usersTables0 = usersTables; filterGender = genderList.FirstOrDefault(x => x.Id == 0); } public void DateSort(int id) { switch (id) { case 1: UsersTables = UsersTables.OrderBy(x => x.Dataofbirth).ToList(); break; case 2: UsersTables = UsersTables.OrderByDescending(x => x.Dataofbirth).ToList(); break; } } void AllFilters() { UsersTables = UsersTables0; if(!string.IsNullOrEmpty(Find)) UsersTables = UsersTables.Where(x => x.Surname.Contains(Find)).ToList(); if (filterGender != null && filterGender.Id != 0)UsersTables = UsersTables.Where(x=>x.GenderNavigation == FilterGender).ToList(); } public void MyProfile() => MainWindowViewModel.Self.UC = new UserPage(MainWindowViewModel.Self.ID); public void Exit() => MainWindowViewModel.Self.UC = new AuthPage(); } }