86 lines
2.5 KiB
C#
86 lines
2.5 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 readonly SyncService _syncService;
|
|
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, SyncService syncService)
|
|
{
|
|
_authService = authService;
|
|
_asistenciaService = asistenciaService;
|
|
_connectivityService = connectivityService;
|
|
_syncService = syncService;
|
|
_ = 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, _syncService, this);
|
|
}
|
|
|
|
public void NavigateToAsistencia()
|
|
{
|
|
CurrentViewTitle = "Asistencia";
|
|
CurrentView = new AsistenciaViewModel(_asistenciaService, _authService, this);
|
|
}
|
|
|
|
public void NavigateToPerfil()
|
|
{
|
|
CurrentViewTitle = "Mi Perfil";
|
|
CurrentView = new PerfilViewModel(_authService, this);
|
|
}
|
|
|
|
public string UsuarioActual => _authService.CurrentUser?.NombreCompleto ?? "";
|
|
}
|