UserListModel.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.ComponentModel;
  7. using System.Windows.Controls;
  8. using System.Windows;
  9. namespace MyWpfApp.models
  10. {
  11. internal class UserListModel:INotifyPropertyChanged
  12. {
  13. List<UserTable> users;
  14. List<Roles> roles;
  15. int idRole;
  16. string surname;
  17. public UserListModel()
  18. {
  19. users = Globals.MyGlobalConnection.UserTable.ToList();
  20. roles = Globals.MyGlobalConnection.Roles.ToList();
  21. roles.Add(new Roles() { ID = 0, Role = "Все роли" });
  22. idRole = 0;
  23. }
  24. public List<UserTable> Users { get=>users; set
  25. {
  26. users = value;
  27. PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Users"));
  28. }
  29. }
  30. public List<Roles> Roles { get => roles; }
  31. public int IdRole { get => idRole;
  32. set
  33. {
  34. idRole = value;
  35. PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IdRole"));
  36. AllFilters();
  37. }
  38. }
  39. public string Surname { get => surname; set
  40. {
  41. surname = value;
  42. PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Surname"));
  43. AllFilters();
  44. }
  45. }
  46. void AllFilters()
  47. {
  48. List<UserTable> userFiltered = Globals.MyGlobalConnection.UserTable.ToList();
  49. if (idRole !=0) userFiltered = userFiltered.Where(x => x.LoginedTable.IDRole == idRole).ToList();
  50. if (surname != null) userFiltered = userFiltered.Where(x => x.Surname.StartsWith(surname)).ToList();
  51. Users = userFiltered;
  52. }
  53. public event PropertyChangedEventHandler PropertyChanged;
  54. }
  55. }