123 lines
2.9 KiB
C#
123 lines
2.9 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Asistencia.Services;
|
|
|
|
namespace Asistencia.ViewModels;
|
|
|
|
public partial class PerfilViewModel : ObservableObject
|
|
{
|
|
private readonly AuthService _authService;
|
|
private readonly MainWindowViewModel _mainVm;
|
|
|
|
[ObservableProperty]
|
|
private string _rut = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _nombreCompleto = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _email = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _fono = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _direccion = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _mensajeExito = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool _tieneExito;
|
|
|
|
[ObservableProperty]
|
|
private string _mensajeError = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool _tieneError;
|
|
|
|
[ObservableProperty]
|
|
private bool _mostrarCambioClave;
|
|
|
|
[ObservableProperty]
|
|
private string _claveActual = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _nuevaClave = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _confirmarClave = string.Empty;
|
|
|
|
public PerfilViewModel(AuthService authService, MainWindowViewModel mainVm)
|
|
{
|
|
_authService = authService;
|
|
_mainVm = mainVm;
|
|
|
|
var user = authService.CurrentUser;
|
|
if (user != null)
|
|
{
|
|
Rut = user.RutPasaporte;
|
|
NombreCompleto = user.NombreCompleto;
|
|
Email = user.Email;
|
|
Fono = user.Fono;
|
|
Direccion = user.Direccion;
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task GuardarEmailAsync()
|
|
{
|
|
TieneExito = false;
|
|
TieneError = false;
|
|
|
|
var (success, message) = await _authService.ActualizarEmailAsync(Email);
|
|
if (success)
|
|
{
|
|
MensajeExito = message;
|
|
TieneExito = true;
|
|
}
|
|
else
|
|
{
|
|
MensajeError = message;
|
|
TieneError = true;
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task CambiarClaveAsync()
|
|
{
|
|
TieneExito = false;
|
|
TieneError = false;
|
|
|
|
var (success, message) = await _authService.CambiarClaveAsync(ClaveActual, NuevaClave, ConfirmarClave);
|
|
if (success)
|
|
{
|
|
MensajeExito = message;
|
|
TieneExito = true;
|
|
MostrarCambioClave = false;
|
|
ClaveActual = string.Empty;
|
|
NuevaClave = string.Empty;
|
|
ConfirmarClave = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
MensajeError = message;
|
|
TieneError = true;
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void ToggleCambioClave()
|
|
{
|
|
MostrarCambioClave = !MostrarCambioClave;
|
|
TieneExito = false;
|
|
TieneError = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Volver()
|
|
{
|
|
_mainVm.NavigateToDashboard();
|
|
}
|
|
}
|