AuthViewModel.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using pr13.Models;
  5. using MsBox.Avalonia.Enums;
  6. using MsBox.Avalonia;
  7. using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
  8. using ReactiveUI;
  9. namespace pr13.ViewModels
  10. {
  11. public class AuthViewModel : ReactiveObject
  12. {
  13. public static PostgresContext DB = new PostgresContext();
  14. private string _login;
  15. private string _pass;
  16. public string Login
  17. {
  18. get => _login; set => this.RaiseAndSetIfChanged(ref _login, value);
  19. }
  20. public string Pass
  21. {
  22. get => _pass; set => this.RaiseAndSetIfChanged(ref _pass, value);
  23. }
  24. public int Auth()
  25. {
  26. if (Login != null && Pass != null)
  27. {
  28. User user = DB.Users.Where(x => x.Login == Login && x.Password == Pass).FirstOrDefault();
  29. if (user != null)
  30. {
  31. return user.IdUser;
  32. }
  33. else
  34. {
  35. var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Òàêîãî àêêàóíòà íå ñóùåñòâóåò");
  36. box.ShowAsync();
  37. return 0;
  38. }
  39. }
  40. else
  41. {
  42. var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëÿ íå çàïîëíåíû");
  43. box.ShowAsync();
  44. return 0;
  45. }
  46. }
  47. }
  48. }