54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Asistencia.Services;
|
|
|
|
namespace Asistencia.ViewModels;
|
|
|
|
public partial class LoginViewModel : ObservableObject
|
|
{
|
|
private readonly AuthService _authService;
|
|
private readonly MainWindowViewModel _mainVm;
|
|
|
|
[ObservableProperty]
|
|
private string _rut = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _password = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _errorMessage = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool _hasError;
|
|
|
|
[ObservableProperty]
|
|
private bool _isLoading;
|
|
|
|
public LoginViewModel(AuthService authService, MainWindowViewModel mainVm)
|
|
{
|
|
_authService = authService;
|
|
_mainVm = mainVm;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task LoginAsync()
|
|
{
|
|
IsLoading = true;
|
|
HasError = false;
|
|
|
|
var (success, message) = await _authService.LoginAsync(Rut, Password);
|
|
|
|
if (success)
|
|
{
|
|
_mainVm.NavigateToDashboard();
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = message;
|
|
HasError = true;
|
|
}
|
|
|
|
IsLoading = false;
|
|
}
|
|
}
|