AuthViewModel.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using HelloItQuantum.Function;
  5. using HelloItQuantum.Models;
  6. using HelloItQuantum.Views;
  7. using ReactiveUI;
  8. namespace HelloItQuantum.ViewModels
  9. {
  10. public class AuthViewModel : MainWindowViewModel
  11. {
  12. #region
  13. string nickname = "";
  14. List<string>? userNicknames = new List<string>();
  15. public string Nickname { get => nickname; set => SetProperty(ref nickname, value); }
  16. #endregion
  17. /// <summary>
  18. /// Ìåòîä, îáðàáàòûâàþùèé íàæàòèå íà êíîïêó Âîéòè
  19. /// </summary>
  20. public void Auth()
  21. {
  22. List<User>? users = WorkWithFile.GetAllUsers();
  23. if(users != null)
  24. {
  25. userNicknames = users.Select(it => it.Nickname).ToList();
  26. if (userNicknames.Contains(Nickname))
  27. {
  28. CurrentUser = users.FirstOrDefault(it => it.Nickname == Nickname);
  29. HomeVM = new HomeViewModel();
  30. PageSwitch.View = new HomeView();
  31. }
  32. else
  33. {
  34. Nickname = "";
  35. }
  36. }
  37. else
  38. {
  39. Nickname = "";
  40. }
  41. }
  42. /// <summary>
  43. /// Ìåòîä, îáðàáàòûâàþùèé íàæàòèå íà êíîïêó Íåò ïðîôèëÿ
  44. /// </summary>
  45. public void CreateProfile()
  46. {
  47. CreateProfileVM = new CreateProfileViewModel();
  48. PageSwitch.View = new CreateProfileView();
  49. }
  50. }
  51. }