AdminPageViewModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Avalonia;
  7. using Avalonia.Controls.ApplicationLifetimes;
  8. using Avalonia.Media.Imaging;
  9. using Avalonia.Platform.Storage;
  10. using AvaloniaHomeTry.Models;
  11. using Microsoft.EntityFrameworkCore;
  12. using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
  13. using ReactiveUI;
  14. using Tmds.DBus.Protocol;
  15. namespace AvaloniaHomeTry.ViewModels
  16. {
  17. public partial class AdminPageViewModel : ViewModelBase
  18. {
  19. UsersTable myUsers = new UsersTable();
  20. List<Gender> genderList;
  21. List<UsersTable> usersTables;
  22. List<UsersTable> usersTables0;
  23. Gender filterGender;
  24. string find;
  25. public List<Gender> GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); }
  26. public List<UsersTable> UsersTables { get => usersTables; set => this.RaiseAndSetIfChanged(ref usersTables, value); }
  27. public List<UsersTable> UsersTables0 { get => usersTables0; set => this.RaiseAndSetIfChanged(ref usersTables0, value); }
  28. public Gender FilterGender { get => filterGender; set { filterGender = value; AllFilters(); } }
  29. public string Find { get => find; set { find = value; AllFilters(); } }
  30. public AdminPageViewModel()
  31. {
  32. usersTables = db.UsersTable.ToList();
  33. genderList = db.Genders.ToList();
  34. genderList.Add(new Gender() { Id = 0, GenderName = "Ñáðîñèòü ôèëüòðû"});
  35. usersTables0 = usersTables;
  36. filterGender = genderList.FirstOrDefault(x => x.Id == 0);
  37. }
  38. public void DateSort(int id)
  39. {
  40. switch (id)
  41. {
  42. case 1:
  43. UsersTables = UsersTables.OrderBy(x => x.Dataofbirth).ToList();
  44. break;
  45. case 2:
  46. UsersTables = UsersTables.OrderByDescending(x => x.Dataofbirth).ToList();
  47. break;
  48. }
  49. }
  50. void AllFilters()
  51. {
  52. UsersTables = UsersTables0;
  53. if(!string.IsNullOrEmpty(Find)) UsersTables = UsersTables.Where(x => x.Surname.Contains(Find)).ToList();
  54. if (filterGender != null && filterGender.Id != 0)UsersTables = UsersTables.Where(x=>x.GenderNavigation == FilterGender).ToList();
  55. }
  56. public void MyProfile() => MainWindowViewModel.Self.UC = new UserPage(MainWindowViewModel.Self.ID);
  57. public void Exit() => MainWindowViewModel.Self.UC = new AuthPage();
  58. }
  59. }