Page6ViewModel.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using ReactiveUI;
  4. using Tmds.DBus.Protocol;
  5. namespace FoodLogProject.ViewModels
  6. {
  7. public class Page6ViewModel : ReactiveObject
  8. {
  9. Customer? currentUser;
  10. GaruaevContext myConnection;
  11. string oldPassowrd;
  12. public Page6ViewModel(Customer? currentUser, GaruaevContext myConnection)
  13. {
  14. this.CurrentUser = currentUser;
  15. this.myConnection = myConnection;
  16. oldPassowrd = currentUser.CustomerPassword;
  17. }
  18. public Customer? CurrentUser { get => currentUser; set => currentUser = value; }
  19. public string Birthday { get => currentUser.CustomerBirthdate.ToString(); set => currentUser.CustomerBirthdate = Convert.ToDateTime(value); }
  20. public string ConfirmPassowrd { get => confirmPassowrd; set => confirmPassowrd = value; }
  21. public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
  22. public bool ChangePassword { get => changePassword; set => this.RaiseAndSetIfChanged(ref changePassword, value); }
  23. string confirmPassowrd;
  24. string message;
  25. bool changePassword;
  26. public void SaveData()
  27. {
  28. if (currentUser.CustomerPassword == null || currentUser.CustomerPassword == "") currentUser.CustomerPassword = oldPassowrd;
  29. if (ChangePassword == (currentUser.CustomerPassword == confirmPassowrd))
  30. {
  31. Message = "Ñîõðàíåíî óñïåøíî";
  32. myConnection.SaveChanges();
  33. }
  34. else
  35. {
  36. Message = "Ïàðîëè íå ñîâïàäàþò";
  37. }
  38. }
  39. }
  40. }