123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reactive.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Avalonia.Media.Imaging;
- using Avalonia.Media.TextFormatting;
- using AvaloniaApplicationTestNew.Models;
- using AvaloniaApplicationTestNew.Views;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using Tmds.DBus.Protocol;
- namespace AvaloniaApplicationTestNew.ViewModels
- {
- public class AdminPageViewModel : ViewModelBase
- {
- List<User> users;
- List<User> users0;
- List<Localuser> localusers;
- List<Gender> genders;
- int idUser;
- string findText;
- Gender filtGendr;
- List<Bitmap> imageUser;
- Dictionary<User, Bitmap> ConvertImage = new Dictionary<User, Bitmap>();
- List<Dictionary<User, Bitmap>> listDictionaries = new List<Dictionary<User, Bitmap>>();
- List<Localuser> localUser;
- public List<User> Users { get => users; set => this.RaiseAndSetIfChanged(ref users, value); }
- public List<User> Users0 { get => users0; set => this.RaiseAndSetIfChanged(ref users0, value); }
- public List<Localuser> LocalListusers { get => localusers; set => this.RaiseAndSetIfChanged(ref localusers, value); }
- public List<Gender> Genders { get => genders; set => this.RaiseAndSetIfChanged(ref genders, value); }
- public string FindText { get => findText; set => this.RaiseAndSetIfChanged(ref findText, value); }
- public Gender FiltGendr { get => filtGendr; set => this.RaiseAndSetIfChanged(ref filtGendr, value); }
- public int IdUser { get => idUser; set => this.RaiseAndSetIfChanged(ref idUser, value); }
- public List<Bitmap> ImageUser { get => imageUser; set => this.RaiseAndSetIfChanged(ref imageUser, value); }
- public List<Dictionary<User, Bitmap>> ListDictionaries { get => listDictionaries; set => this.RaiseAndSetIfChanged(ref listDictionaries, value); }
- public AdminPageViewModel()
- {
- Users = myContext.Users.Include(x => x.IdUserNavigation.IdRoleNavigation).Include(x => x.IdGenderNavigation).Include(x => x.IdTraits).ToList();
- int count = 0;
- LocalListusers = RemakeList(users);
- localUser = LocalListusers;
- genders = new List<Gender>
- {
- new Gender() {Gender1 = "Сбросить фильтр", IdGender = 0}
- }.Concat(myContext.Genders).ToList(); FiltGendr = genders[0];
- users0 = users;
- this.WhenAnyValue(x => x.FindText, x => x.FiltGendr).Subscribe(_ => AllFilters());
- }
- public List<Localuser> RemakeList(List<User> users)
- {
- List<Localuser> LocalListusers = new List<Localuser>();
- foreach (var user in users)
- {
- Localuser temp =
- new Localuser
- {
- Name = user.Name,
- IdGender = user.IdGender,
- IdGenderNavigation = user.IdGenderNavigation,
- IdUser = user.IdUser,
- IdUserNavigation = user.IdUserNavigation,
- BirthDate = user.BirthDate,
- IdTraits = user.IdTraits,
- ConvertImage = user.Image != null ? new Bitmap(new MemoryStream(user.Image)) : new Bitmap("Assets\\ava.png")
- };
- LocalListusers.Add(temp);
- }
- return LocalListusers;
- }
- public void OnTextFindChanged(string text) => AllFilters();
- public void SortDate(int id)
- {
- switch (id)
- {
- case 1:
- LocalListusers = LocalListusers.OrderBy(x => x.BirthDate).ToList();
- break;
- case 2:
- LocalListusers = LocalListusers.OrderByDescending(x => x.BirthDate).ToList();
- break;
- }
- }
- public void OnFilterGenderChanged(Gender meaning) => AllFilters();
- void AllFilters()
- {
- LocalListusers = localUser;
- if (!string.IsNullOrEmpty(findText)) LocalListusers = LocalListusers.Where(x => x.Name.Contains(findText)).ToList();
- if (filtGendr != null && filtGendr.IdGender != 0) LocalListusers = LocalListusers.Where(x => x.IdGenderNavigation == filtGendr).ToList();
- }
- public void InfoUsers(int id)
- {
- IdUser = id;
- MainWindowViewModel.Self.UserPageVM = new UserPageViewModel(id);
- MainWindowViewModel.Self.Page = new UserPage();
- }
- public void AddUser()
- {
- MainWindowViewModel.Self.AddUserPageVM = new AddUserPageViewModel();
- MainWindowViewModel.Self.Page = new AddUserPage();
- }
- public void Exit()
- {
- MainWindowViewModel.Self.AuthorizationVM = new AuthorizationViewModel();
- MainWindowViewModel.Self.Page = new Authorization();
- }
- }
- }
|