- 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
84 lines
2.4 KiB
C#
84 lines
2.4 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Asistencia.Models;
|
|
using Asistencia.Services;
|
|
using Avalonia.Controls;
|
|
using Asistencia.Views;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Asistencia.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
private readonly AuthService _authService;
|
|
private readonly AsistenciaService _asistenciaService;
|
|
private readonly ConnectivityService _connectivityService;
|
|
private object? _currentView;
|
|
|
|
[ObservableProperty]
|
|
private string _currentViewTitle = "Login";
|
|
|
|
[ObservableProperty]
|
|
private bool _conexionDisponible;
|
|
|
|
[ObservableProperty]
|
|
private string _mensajeConexion = string.Empty;
|
|
|
|
public object? CurrentView
|
|
{
|
|
get => _currentView;
|
|
set => SetProperty(ref _currentView, value);
|
|
}
|
|
|
|
public MainWindowViewModel(AuthService authService, AsistenciaService asistenciaService, ConnectivityService connectivityService)
|
|
{
|
|
_authService = authService;
|
|
_asistenciaService = asistenciaService;
|
|
_connectivityService = connectivityService;
|
|
_ = VerificarConexionAsync();
|
|
}
|
|
|
|
private async Task VerificarConexionAsync()
|
|
{
|
|
var hayInternet = await _connectivityService.HayConexionAsync();
|
|
ConexionDisponible = hayInternet;
|
|
|
|
if (hayInternet)
|
|
{
|
|
MensajeConexion = "Aplicación no disponible con conexión a internet. Desconéctese para usar el sistema.";
|
|
CurrentView = null;
|
|
}
|
|
else
|
|
{
|
|
MensajeConexion = "Modo offline — Using local database";
|
|
CurrentView = new LoginViewModel(_authService, this);
|
|
}
|
|
}
|
|
|
|
public void NavigateToLogin()
|
|
{
|
|
CurrentViewTitle = "Login";
|
|
CurrentView = new LoginViewModel(_authService, this);
|
|
}
|
|
|
|
public void NavigateToDashboard()
|
|
{
|
|
CurrentViewTitle = "Panel Principal";
|
|
CurrentView = new DashboardViewModel(_authService, _asistenciaService, this);
|
|
}
|
|
|
|
public void NavigateToAsistencia(CursoAbierto curso)
|
|
{
|
|
CurrentViewTitle = "Asistencia";
|
|
CurrentView = new AsistenciaViewModel(_asistenciaService, _authService, curso, this);
|
|
}
|
|
|
|
public void NavigateToPerfil()
|
|
{
|
|
CurrentViewTitle = "Mi Perfil";
|
|
CurrentView = new PerfilViewModel(_authService, this);
|
|
}
|
|
|
|
public string UsuarioActual => _authService.CurrentUser?.NombreCompleto ?? "";
|
|
}
|