|
@@ -0,0 +1,65 @@
|
|
|
+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;
|
|
|
+ }
|
|
|
+}
|