76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Asistencia.Models;
|
|
using Asistencia.Services;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Asistencia.ViewModels;
|
|
|
|
public partial class DashboardViewModel : ViewModelBase
|
|
{
|
|
private readonly AuthService _authService;
|
|
private readonly AsistenciaService _asistenciaService;
|
|
private readonly SyncService _syncService;
|
|
private readonly MainWindowViewModel _mainVm;
|
|
|
|
[ObservableProperty]
|
|
private string _nombreProfesor = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _tipoAsignacion = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private int _pendientes;
|
|
|
|
[ObservableProperty]
|
|
private string _mensajeSync = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool _hasMensajeSync;
|
|
|
|
public DashboardViewModel(AuthService authService, AsistenciaService asistenciaService, SyncService syncService, MainWindowViewModel mainVm)
|
|
{
|
|
_authService = authService;
|
|
_asistenciaService = asistenciaService;
|
|
_syncService = syncService;
|
|
_mainVm = mainVm;
|
|
NombreProfesor = authService.CurrentUser?.NombreCompleto ?? "";
|
|
TipoAsignacion = authService.TipoAsignacionActual == 1 ? "Titular" : "Reemplazo";
|
|
_ = CargarPendientesAsync();
|
|
}
|
|
|
|
private async Task CargarPendientesAsync()
|
|
{
|
|
Pendientes = await _syncService.ContarPendientesAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void AbrirAsistencia()
|
|
{
|
|
_mainVm.NavigateToAsistencia();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task SincronizarAsync()
|
|
{
|
|
HasMensajeSync = false;
|
|
var (success, message) = await _syncService.SincronizarAsync("http://localhost:5000");
|
|
MensajeSync = message;
|
|
HasMensajeSync = true;
|
|
await CargarPendientesAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void AbrirPerfil()
|
|
{
|
|
_mainVm.NavigateToPerfil();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void CerrarSesion()
|
|
{
|
|
_authService.Logout();
|
|
_mainVm.NavigateToLogin();
|
|
}
|
|
}
|