2024-12-22 12:37:22 +00:00
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
using presence.data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
using presence.domain.Models;
|
|
|
|
using presence.domain.UseCase;
|
|
|
|
using Presence.Desktop.Models;
|
|
|
|
using Presence.Desktop.ViewModels;
|
|
|
|
using ReactiveUI;
|
|
|
|
using System;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Reactive;
|
2024-12-13 07:21:14 +00:00
|
|
|
|
2024-12-22 12:37:22 +00:00
|
|
|
namespace Presence.Desktop.ViewModels
|
2024-12-13 07:21:14 +00:00
|
|
|
{
|
2024-12-22 12:37:22 +00:00
|
|
|
public class PresenceViewModel : ViewModelBase, IRoutableViewModel
|
|
|
|
{
|
|
|
|
public string? UrlPathSegment { get; } = "Presence";
|
|
|
|
public IScreen HostScreen { get; }
|
|
|
|
|
|
|
|
private readonly GroupUseCase _groupUseCase;
|
|
|
|
private readonly PresenceUseCase _presenceUseCase;
|
|
|
|
|
|
|
|
public ObservableCollection<PresencePresenter> AttendanceRecords { get; set; } = new();
|
|
|
|
public ObservableCollection<GroupPresenter> Groups { get; set; } = new();
|
|
|
|
|
|
|
|
private GroupPresenter? _selectedGroup;
|
|
|
|
public GroupPresenter? SelectedGroup
|
|
|
|
{
|
|
|
|
get => _selectedGroup;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
this.RaiseAndSetIfChanged(ref _selectedGroup, value);
|
|
|
|
FilterAttendanceRecords();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-23 11:56:27 +00:00
|
|
|
private DateTime? _selectedDate;
|
|
|
|
public DateTime? SelectedDate
|
2024-12-22 12:37:22 +00:00
|
|
|
{
|
|
|
|
get => _selectedDate;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
this.RaiseAndSetIfChanged(ref _selectedDate, value);
|
|
|
|
FilterAttendanceRecords();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> NavigateBackCommand { get; }
|
|
|
|
|
2024-12-23 11:56:27 +00:00
|
|
|
public PresenceViewModel(GroupUseCase groupUseCase, PresenceUseCase presenceUseCase)
|
2024-12-22 12:37:22 +00:00
|
|
|
{
|
|
|
|
_groupUseCase = groupUseCase;
|
|
|
|
|
2024-12-23 11:56:27 +00:00
|
|
|
_presenceUseCase = presenceUseCase;
|
|
|
|
|
2024-12-22 12:37:22 +00:00
|
|
|
|
|
|
|
NavigateBackCommand = ReactiveCommand.Create(() => { });
|
|
|
|
|
2024-12-23 11:56:27 +00:00
|
|
|
this.WhenAnyValue(vm => vm.SelectedGroup)
|
|
|
|
.Subscribe(_ =>
|
|
|
|
{
|
|
|
|
LoadGroups();
|
|
|
|
});
|
2024-12-22 12:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void LoadGroups()
|
|
|
|
{
|
|
|
|
Groups.Clear();
|
|
|
|
var groups = _groupUseCase.GetAllGroups();
|
|
|
|
|
|
|
|
foreach (var group in groups)
|
|
|
|
{
|
|
|
|
Groups.Add(new GroupPresenter
|
|
|
|
{
|
|
|
|
Id = group.Id,
|
|
|
|
Name = group.Name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FilterAttendanceRecords()
|
|
|
|
{
|
2024-12-23 11:56:27 +00:00
|
|
|
if (SelectedGroup == null)
|
2024-12-22 12:37:22 +00:00
|
|
|
{
|
|
|
|
AttendanceRecords.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var records = _presenceUseCase.GetPresenceByGroupAndDate(
|
|
|
|
SelectedGroup.Id,
|
2024-12-23 11:56:27 +00:00
|
|
|
DateOnly.FromDateTime(SelectedDate.Value));
|
2024-12-13 07:21:14 +00:00
|
|
|
|
2024-12-22 12:37:22 +00:00
|
|
|
AttendanceRecords.Clear();
|
|
|
|
foreach (var record in records)
|
|
|
|
{
|
|
|
|
AttendanceRecords.Add(new PresencePresenter
|
|
|
|
{
|
2024-12-23 11:56:27 +00:00
|
|
|
Id = record.Id,
|
2024-12-22 12:37:22 +00:00
|
|
|
Date = record.Date,
|
|
|
|
ClassNumber = record.ClassNumber,
|
|
|
|
IsAttendence = record.IsAttendence,
|
|
|
|
User = new UserPresenter
|
|
|
|
{
|
|
|
|
Id = record.User.Id,
|
|
|
|
Name= record.User.FIO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2024-12-13 07:21:14 +00:00
|
|
|
|
2024-12-22 12:37:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|