Page2ViewModel.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Avalonia.Controls.ApplicationLifetimes;
  2. using reactivepril.Models;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Avalonia;
  9. using Avalonia.Platform.Storage;
  10. using Avalonia.Media.Imaging;
  11. using System.IO;
  12. using ReactiveUI;
  13. using Avalonia.Media.TextFormatting;
  14. using Avalonia.Controls;
  15. namespace reactivepril.ViewModels
  16. {
  17. public class Page2ViewModel : ReactiveObject
  18. {
  19. public Galochkin41pContext db = new Galochkin41pContext();
  20. List<User> users;
  21. List<User> users0;
  22. User editedUser;
  23. List<Gender> genderList;
  24. string textFind;
  25. Gender filteredGender;
  26. Bitmap imageUser;
  27. UserControl page;
  28. MainWindowViewModel MainVM;
  29. int id;
  30. public User EditedUser { get => editedUser; set => this.RaiseAndSetIfChanged(ref editedUser, value); }
  31. public List<User> Users0 { get => users0; set => this.RaiseAndSetIfChanged(ref users0, value); }
  32. public List<User> Users { get => users; set => this.RaiseAndSetIfChanged(ref users, value); }
  33. public List<Gender> GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); }
  34. public string TextFind { get => textFind; set { textFind = value; AllFilters(); } }
  35. public Gender FilteredGender { get => filteredGender; set { filteredGender = value; AllFilters(); } }
  36. public Bitmap ImageUser { get => imageUser; set => this.RaiseAndSetIfChanged(ref imageUser, value); }
  37. public UserControl Page { get => page; set => this.RaiseAndSetIfChanged(ref page, value); }
  38. public MainWindowViewModel MainVM1 { get => MainVM; set => this.RaiseAndSetIfChanged(ref MainVM, value); }
  39. public int Id { get => id; set => this.RaiseAndSetIfChanged(ref id, value); }
  40. public Page2ViewModel()
  41. {
  42. users = db.Users.ToList();
  43. GenderList = db.Genders.ToList();
  44. genderList.Add(new Gender() {IdGender = 0, NameGender = "ñáðîñèòü ôèëüòðû" });
  45. users0 =users;
  46. filteredGender = genderList.FirstOrDefault(x => x.IdGender == 0);
  47. }
  48. public void OnTextFindChanged(string value) => AllFilters();
  49. void AllFilters()
  50. {
  51. Users = Users0;
  52. if (!string.IsNullOrEmpty(TextFind)) Users = Users.Where(x => x.Name.Contains(TextFind)).ToList();
  53. if (filteredGender != null && filteredGender.IdGender != 0) Users = Users.Where(x => x.GendersNavigation == filteredGender).ToList();
  54. }
  55. public void GoBack()
  56. {
  57. MainWindowViewModel.Self.Page = new Page1();
  58. }
  59. public void GoToProf(int id)
  60. {
  61. MainWindowViewModel.Self.Page = new Page2Next(id);
  62. }
  63. }
  64. }