- Modelos renombrados para coincidir con columnas de MariaDB (ApPaterno/ApMaterno, HoraSalida, FechaFin, IdAsistenciaProfesor) - Agregado campo IdAlumno a DetalleContrato - Seed data con IDs reales de produccion (16451, 16493, profesor 15668563-1) - Login offline: solo valida RUT contra BD local, sin contraseña - ConnectivityService: checkea internet al inicio, bloquea si hay conexion - ViewLocator corregido: busca tipos en todos los ensamblados - Todos los ViewModels heredan de ViewModelBase - Publicacion self-contained para win-x64, linux-x64, osx-x64, osx-arm64 - Agregado .gitignore, removidos bin/obj/publish del tracking
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 : ViewModelBase
|
|
{
|
|
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;
|
|
}
|
|
}
|