123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections.Generic;
- using Avalonia.Controls;
- using AvaloniaApplication5.Models;
- using AvaloniaApplication5.Views;
- using Microsoft.EntityFrameworkCore;
- using System.Linq;
- using ReactiveUI;
- namespace AvaloniaApplication5.ViewModels
- {
- public class PageUserListViewModel : ReactiveObject
- {
- _1234Context DBConnect;
-
- public PageUserListViewModel(_1234Context dBConnect)
- {
- this.DBConnect = dBConnect;
- userList = DBConnect.Logintables.Include(x => x.IdRoleNavigation).Include(x => x.User.IdGenderNavigation).ToList();
- }
- List<Logintable> userList;
- public List<Logintable> UserList { get => userList; set => this.RaiseAndSetIfChanged(ref userList, value); }
-
- public List<string> OrdersName => new List<string>() { "Ïî âîçðàñòàíèþ", "Ïî óáûâàíèþ" };
- string orderByName = "Ïî âîçðàñòàíèþ";
- public string OrderByName
- {
- get => orderByName;
- set
- {
- orderByName = value;
- AllFilters();
- }
- }
- public List<string> Genders//ñïèñîê ïîëîâ äëÿ ôèëüòðà
- {
- get
- {
- List<string> newlist = new List<string>() { "Ëþáîé" };
- newlist.AddRange(DBConnect.Genders.Select(x => x.Gender1).ToList());
- return newlist;
- }
- }
- string filterByGender = "Ëþáîé";
- public string FilterByGender
- {
- get => filterByGender;
- set
- {
- filterByGender = value;
- AllFilters();
- }
- }
- string namefind;
- public string Namefind { get => namefind; set { namefind = value; AllFilters(); } }
-
- void AllFilters()
- {
- //âñåãäà ïåðåä ñîðòèðîâêîé ïîëó÷àåì íîâûé ëèñò
- userList = DBConnect.Logintables.Include(x => x.IdRoleNavigation).Include(x => x.User.IdGenderNavigation).ToList();
- //ïîèñê ïî èìåíè
- if (!(namefind == "" || namefind == null))
- UserList = UserList.Where(x => x.User.Name.Contains(namefind)).ToList();
- //ñîðòèðîâêà ïî âîçðàñòàíèþ èìåíè
- switch (orderByName)
- {
- case "Ïî âîçðàñòàíèþ":
- UserList = UserList.OrderBy(x => x.User.Name).ToList();
- break;
- case "Ïî óáûâàíèþ":
- UserList = UserList.OrderByDescending(x => x.User.Name).ToList();
- break;
- }
- //ôèëüòð ïî ïîëó
- if (!(filterByGender == "Ëþáîé" || filterByGender == null))
- UserList = UserList.Where(x => x.User.IdGenderNavigation.Gender1 == filterByGender).ToList();
-
- }
- }
- }
|