MainWindowViewModel.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using AvaloniaApplication4.AdditionalModels;
  2. using AvaloniaApplication4.Models;
  3. using AvaloniaApplication4.Views;
  4. using Microsoft.EntityFrameworkCore;
  5. using ReactiveUI;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. namespace AvaloniaApplication4.ViewModels
  9. {
  10. public class MainWindowViewModel : ViewModelBase
  11. {
  12. private string? message = "";
  13. public string? Login { get; set; }
  14. public string? Password { get; set; }
  15. public string? Message
  16. {
  17. get { return message; }
  18. set
  19. {
  20. if (message == value)
  21. return;
  22. message = value;
  23. OnPropertyChanged("Message");
  24. }
  25. }
  26. GlobalsData globalsData = new();
  27. public GlobalsData GlobalsData { get => globalsData; set => globalsData = value; }
  28. public MainWindowViewModel()
  29. {
  30. globalsData = new GlobalsData();
  31. //GlobalsData.GlobalUserControl = new StartPage(user);
  32. }
  33. public void Next()
  34. {
  35. try
  36. {
  37. UsersLogin? currentUser = dataBase.UsersLogins.FirstOrDefault(x => x.Password == Password && x.UserEmail == Login);
  38. User? user;
  39. if (currentUser == null) Message = "Неверный логин или пароль";
  40. else
  41. {
  42. Message = "";
  43. user = dataBase.Users.FirstOrDefault(x => x.IdUser == currentUser.IdUser);
  44. MainUserControl = new MainPage(user);
  45. }
  46. }
  47. catch { }
  48. }
  49. }
  50. }