MainWindowViewModel.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Avalonia.Controls;
  2. using ReactiveUI;
  3. using System.Linq;
  4. namespace prakt1314.ViewModels
  5. {
  6. public class MainWindowViewModel : ViewModelBase
  7. {
  8. public MainWindowViewModel()
  9. {
  10. AuthPageViewModel apvm = new AuthPageViewModel();
  11. apvm.NotifyUserWasSuccessfulAuthorize += NotifyUserWasSuccessfulAuthorize;
  12. UserControl = (new ViewLocator()).Build(apvm);
  13. }
  14. private void NotifyUserWasSuccessfulAuthorize(int userID)
  15. {
  16. _userID = userID;
  17. UserRole role;
  18. using (AvaloniaPrakt13DbContext _dbContextForThis = new AvaloniaPrakt13DbContext()) role = _dbContextForThis.UserRoles.Where(a => (a.UserLogins.Where(a => a.IdUser == userID)).LongCount() == 1).First();
  19. switch (role.IdRole)
  20. {
  21. case 1:
  22. {
  23. CourcesListViewModel CLVM = new CourcesListViewModel();
  24. UserControl = (new ViewLocator()).Build(CLVM);
  25. break;
  26. }
  27. case 2:
  28. {
  29. CabinetViewModel CVM = new CabinetViewModel(_userID);
  30. UserControl = (new ViewLocator()).Build(CVM);
  31. return;
  32. }
  33. default:
  34. {
  35. return;
  36. }
  37. }
  38. }
  39. public Control UserControl
  40. {
  41. get => _userControl;
  42. set => this.RaiseAndSetIfChanged(ref _userControl, value);
  43. }
  44. private Control _userControl;
  45. private int _userID;
  46. }
  47. }