UserViewModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Acosta.Models;
  5. using ReactiveUI;
  6. namespace Acosta.ViewModels
  7. {
  8. public class UserViewModel : ReactiveObject
  9. {
  10. SuharevaContext myConnection;
  11. Employee? currentUser;
  12. public UserViewModel(SuharevaContext myC)
  13. {
  14. this.myConnection = myC;
  15. CurrentUser = new Employee();
  16. }
  17. public UserViewModel(SuharevaContext myConnection, int id, string password)
  18. {
  19. this.myConnection = myConnection;
  20. currentUser = myConnection.Employees.FirstOrDefault(x => x.Employeesid == id);
  21. if (password == CurrentUser.Password)
  22. {
  23. currentUser.Surname = currentUser.Surname;
  24. currentUser.Name = currentUser.Name;
  25. currentUser.Patronymic = currentUser.Patronymic;
  26. currentUser.Email = currentUser.Email;
  27. currentUser.Phonenumber = currentUser.Phonenumber;
  28. currentUser.Role = currentUser.Role;
  29. currentUser.Password = password;
  30. myConnection.SaveChanges();
  31. }
  32. }
  33. public Employee? CurrentUser { get => currentUser; set => currentUser = value; }
  34. }
  35. }