MyDiplom/ViewModels/UserViewModels.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2025-03-14 09:56:57 +03:00
using MyDiplom.Models;
using System;
using System.Collections.Generic;
2025-04-14 12:49:39 +03:00
using System.ComponentModel;
2025-03-14 09:56:57 +03:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2025-04-14 12:49:39 +03:00
using Windows.System;
2025-03-14 09:56:57 +03:00
namespace MyDiplom.ViewModels
{
2025-04-14 12:49:39 +03:00
public class UserViewModels : BaseViewModel
2025-03-14 09:56:57 +03:00
{
public ApplicationUser User { get; set; } = new ApplicationUser();
public UserViewModels()
{
2025-04-14 12:49:39 +03:00
User = new ApplicationUser { DisplayName = "Вася" };
LoadUserData();
}
public void UpdateBalance(decimal amount)
{
if (amount != 0)
{
User.Balance += amount;
OnPropertyChanged(nameof(User));
SaveUserData();
}
}
private void SaveUserData()
{
Preferences.Set("UserBalance", User.Balance.ToString());
Preferences.Set("UserDisplayName", User.DisplayName);
}
private void LoadUserData()
{
string balanceString = Preferences.Get("UserBalance", "0");
User.Balance = decimal.TryParse(balanceString, out var balance) ? balance : 0;
User.DisplayName = Preferences.Get("UserDisplayName", "Вася");
2025-03-14 09:56:57 +03:00
}
2025-04-14 12:49:39 +03:00
2025-03-14 09:56:57 +03:00
}
}