1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.ComponentModel;
- using System.Windows.Controls;
- using System.Windows;
- namespace MyWpfApp.models
- {
- internal class UserListModel:INotifyPropertyChanged
- {
- List<UserTable> users;
- List<Roles> roles;
- int idRole;
- string surname;
- public UserListModel()
- {
- users = Globals.MyGlobalConnection.UserTable.ToList();
- roles = Globals.MyGlobalConnection.Roles.ToList();
- roles.Add(new Roles() { ID = 0, Role = "Все роли" });
- idRole = 0;
- }
- public List<UserTable> Users { get=>users; set
- {
- users = value;
- PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Users"));
- }
- }
- public List<Roles> Roles { get => roles; }
- public int IdRole { get => idRole;
- set
- {
- idRole = value;
- PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IdRole"));
- AllFilters();
- }
- }
- public string Surname { get => surname; set
- {
- surname = value;
- PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Surname"));
- AllFilters();
- }
- }
- void AllFilters()
- {
- List<UserTable> userFiltered = Globals.MyGlobalConnection.UserTable.ToList();
- if (idRole !=0) userFiltered = userFiltered.Where(x => x.LoginedTable.IDRole == idRole).ToList();
- if (surname != null) userFiltered = userFiltered.Where(x => x.Surname.StartsWith(surname)).ToList();
- Users = userFiltered;
- }
- public event PropertyChangedEventHandler PropertyChanged;
- }
- }
|