|
1 |
| -namespace MyFinance.ViewModels; |
| 1 | + |
| 2 | +namespace MyFinance.ViewModels; |
2 | 3 |
|
3 | 4 | public partial class AccountPageViewModel : BaseViewModel
|
4 | 5 | {
|
| 6 | + private readonly IUserRepo _userRepo; |
| 7 | + |
| 8 | + [ObservableProperty] |
| 9 | + private User userModel = new() |
| 10 | + { |
| 11 | + Email = string.Empty, |
| 12 | + FirstName = string.Empty, |
| 13 | + LastName = string.Empty, |
| 14 | + Password = string.Empty |
| 15 | + }; |
| 16 | + |
| 17 | + [ObservableProperty] |
| 18 | + private UserCardVM user = new(); |
| 19 | + |
| 20 | + [ObservableProperty] |
| 21 | + private bool isPopupShow = false; |
| 22 | + |
| 23 | + [ObservableProperty] |
| 24 | + private bool isInfoPopupShow = false; |
| 25 | + |
| 26 | + [ObservableProperty] |
| 27 | + private Color infoPopupColor = SkyBlue; |
| 28 | + |
| 29 | + [ObservableProperty] |
| 30 | + private string infoPopupTitle = "BİLGİ"; |
| 31 | + |
| 32 | + [ObservableProperty] |
| 33 | + private string infoPopupDesc = "İşlem başarılı olmuştur."; |
| 34 | + |
| 35 | + public AccountPageViewModel(IUserRepo userRepo) |
| 36 | + { |
| 37 | + _userRepo = userRepo; |
| 38 | + var accessUser = AuthCheckHelper.ParseBasicAuthToken(SecureStorage.GetAsync("USERAUTH").Result); |
| 39 | + var currentUser = _userRepo.GetSingleAsync(e => e.Email == accessUser.Item1 && e.Password == accessUser.Item2).Result; |
| 40 | + |
| 41 | + if (currentUser == null) |
| 42 | + currentUser = default; |
| 43 | + |
| 44 | + UserModel = currentUser; |
| 45 | + |
| 46 | + User = new() |
| 47 | + { |
| 48 | + Name = $"{currentUser?.FirstName} {currentUser?.LastName}", |
| 49 | + Email = currentUser?.Email ?? string.Empty |
| 50 | + }; |
| 51 | + } |
| 52 | + |
| 53 | + [RelayCommand] |
| 54 | + public void ShowDetails() |
| 55 | + { |
| 56 | + IsPopupShow = true; |
| 57 | + } |
| 58 | + |
| 59 | + [RelayCommand] |
| 60 | + public void ClosePopup() |
| 61 | + { |
| 62 | + if (InfoPopupTitle == "BİLGİ") |
| 63 | + { |
| 64 | + IsInfoPopupShow = false; |
| 65 | + IsPopupShow = false; |
| 66 | + } |
| 67 | + else |
| 68 | + IsInfoPopupShow = false; |
| 69 | + } |
| 70 | + |
| 71 | + [RelayCommand] |
| 72 | + public void CloseDetailsPopup() |
| 73 | + { |
| 74 | + IsPopupShow = false; |
| 75 | + } |
| 76 | + |
| 77 | + [RelayCommand] |
| 78 | + public async void Logout() |
| 79 | + { |
| 80 | + SecureStorage.Remove("USERAUTH"); |
| 81 | + await AppShell.Current.GoToAsync($"//{nameof(LoginPage)}"); |
| 82 | + } |
| 83 | + |
| 84 | + [RelayCommand] |
| 85 | + public async Task Save() |
| 86 | + { |
| 87 | + var result = await _userRepo.UpdateAsync(UserModel); |
| 88 | + if (result) |
| 89 | + { |
| 90 | + InfoPopupColor = SkyBlue; |
| 91 | + InfoPopupTitle = "BİLGİ"; |
| 92 | + infoPopupDesc = "İşlem başarılı olmuştur."; |
| 93 | + } |
| 94 | + else |
| 95 | + { |
| 96 | + InfoPopupColor = DarkOrange; |
| 97 | + InfoPopupTitle = "HATA"; |
| 98 | + infoPopupDesc = "İşlem sırasında beklenmeyen bir hata oluştu."; |
| 99 | + } |
| 100 | + IsInfoPopupShow = true; |
| 101 | + } |
5 | 102 | }
|
0 commit comments