MainWindowViewModel.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Avalonia.Controls;
  2. using AvaloniaHomeTry.Models;
  3. using AvaloniaHomeTry.Views;
  4. using ReactiveUI;
  5. using System.Linq;
  6. namespace AvaloniaHomeTry.ViewModels
  7. {
  8. public class MainWindowViewModel : ViewModelBase
  9. {
  10. public int ID;
  11. private UserControl uc = new AuthPage();
  12. public UserControl UC { get => uc; set =>this.RaiseAndSetIfChanged(ref uc, value); }
  13. AuthPageViewModel contentDbVM = new AuthPageViewModel();
  14. public AuthPageViewModel ContentDbVM { get => contentDbVM; set => contentDbVM = value; }
  15. public static MainWindowViewModel Self;
  16. public MainWindowViewModel()
  17. {
  18. Self = this;
  19. }
  20. public void Registration() => MainWindowViewModel.Self.UC = new RegistrationPage();
  21. public void Enter()
  22. {
  23. UsersTable? currentUser = db.UsersTable.FirstOrDefault(x=>x.Login == ContentDbVM.Login && x.Password == ContentDbVM.Password);
  24. if (currentUser == null)
  25. {
  26. ContentDbVM.Message = "Нет такого пользователя";
  27. }
  28. else
  29. {
  30. ID = currentUser.Id;
  31. switch (currentUser.IdRole)
  32. {
  33. case 1:
  34. UC = new AdminPage();
  35. break;
  36. case 2:
  37. UC = new UserPage(currentUser.Id);
  38. break;
  39. }
  40. }
  41. }
  42. }
  43. }