MainWindowViewModel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. namespace WpfApp4.ViewModel
  9. {
  10. public class MainWindowViewModel:BaseViewModel
  11. {
  12. private User user;
  13. private ObservableCollection<User> users;
  14. private RelayCommand welcom;
  15. private RelayCommand registration;
  16. public RelayCommand Welcom
  17. {
  18. get
  19. {
  20. return welcom ??
  21. (welcom = new RelayCommand(x =>
  22. {
  23. HelpContext helpContext = new HelpContext();
  24. User user = helpContext.Users.FirstOrDefault(y => y.Login == User.Login && y.Password == User.Password);
  25. if (user != null)
  26. {
  27. User.AutoUser = user;
  28. Profil profil= new Profil();
  29. profil.Show();
  30. foreach (var window in App.Current.Windows)
  31. {
  32. if (window is MainWindow mainWindow)
  33. {
  34. mainWindow.Close();
  35. }
  36. }
  37. }
  38. else
  39. {
  40. MessageBox.Show("Данные введены неверно!");
  41. }
  42. }
  43. ));
  44. }
  45. }
  46. public RelayCommand Registration
  47. {
  48. get
  49. {
  50. return registration ?? (registration = new RelayCommand(x =>
  51. {
  52. Registration window2 = new Registration();
  53. window2.Show();
  54. foreach (var window in App.Current.Windows)
  55. {
  56. if (window is MainWindow mainWindow)
  57. {
  58. mainWindow.Close();
  59. }
  60. }
  61. }
  62. ));
  63. }
  64. }
  65. public User User
  66. {
  67. get => user;
  68. set
  69. {
  70. user = value;
  71. OnPropertyChanged();
  72. }
  73. }
  74. public ObservableCollection<User> Users
  75. {
  76. get => users;
  77. set
  78. {
  79. users = value;
  80. OnPropertyChanged();
  81. }
  82. }
  83. public MainWindowViewModel()
  84. {
  85. HelpContext helpContext = new HelpContext();
  86. Users = new ObservableCollection<User>(helpContext.Users);
  87. User = new User();
  88. }
  89. }
  90. }