MainWindowViewModel.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Avalonia.Controls;
  2. using AvaloniaApplication1.Models;
  3. using ReactiveUI;
  4. using System.Linq;
  5. using System.Net;
  6. namespace AvaloniaApplication1.ViewModels
  7. {
  8. public class MainWindowViewModel : ViewModelBase
  9. {
  10. public static ScoolContext DB = new ScoolContext();
  11. UserControl us = new Authorization();
  12. public UserControl US
  13. {
  14. get => us;
  15. set => this.RaiseAndSetIfChanged(ref us, value);
  16. }
  17. AuthorizationViewModel authorizationvm = new AuthorizationViewModel();
  18. PersonalPageViewModel personalpagevm;
  19. CoursesListViewModel coursesvm = new CoursesListViewModel();
  20. public AuthorizationViewModel AuthorizationVM
  21. {
  22. get => authorizationvm;
  23. set => authorizationvm = value;
  24. }
  25. public PersonalPageViewModel PPVM
  26. {
  27. get => personalpagevm;
  28. set => personalpagevm = value;
  29. }
  30. public CoursesListViewModel CourseVM
  31. {
  32. get => coursesvm;
  33. set => coursesvm = value;
  34. }
  35. public void GoAuth()
  36. {
  37. int index = AuthorizationVM.Auth();
  38. if (index != 0)
  39. {
  40. if(DB.Users.Where(x=>x.IdUser == index).Select(x=>x.IdRole).FirstOrDefault()==2)
  41. {
  42. PPVM = new PersonalPageViewModel(index);
  43. US = new PersonalPage();
  44. }
  45. else
  46. {
  47. US = new CoursesList();
  48. }
  49. }
  50. }
  51. }
  52. }