2025-04-21 09:00:17 +00:00
|
|
|
|
// using System.Reactive;
|
|
|
|
|
// using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
// namespace Presence.Desktop.ViewModels;
|
|
|
|
|
|
|
|
|
|
// public class PresenceViewModel: ViewModelBase, IRoutableViewModel
|
|
|
|
|
// {
|
|
|
|
|
// public string? UrlPathSegment { get; }
|
|
|
|
|
// public IScreen HostScreen { get; }
|
|
|
|
|
|
|
|
|
|
// public ReactiveCommand<Unit, Unit> GoBackCommand { get; }
|
|
|
|
|
|
|
|
|
|
// public PresenceViewModel(IScreen hostScreen)
|
|
|
|
|
// {
|
|
|
|
|
// HostScreen = hostScreen;
|
|
|
|
|
|
|
|
|
|
// GoBackCommand = ReactiveCommand.Create(() =>
|
|
|
|
|
// {
|
|
|
|
|
// HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen));
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
using System;
|
2024-12-23 15:12:32 +00:00
|
|
|
|
using System.Reactive;
|
2024-12-04 19:33:12 +00:00
|
|
|
|
using ReactiveUI;
|
2025-04-21 09:00:17 +00:00
|
|
|
|
using Demo.Domain.Models;
|
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using Presence.Desktop.Models;
|
2024-12-04 19:33:12 +00:00
|
|
|
|
|
2025-04-21 09:00:17 +00:00
|
|
|
|
namespace Presence.Desktop.ViewModels
|
2024-12-04 19:33:12 +00:00
|
|
|
|
{
|
2025-04-21 09:00:17 +00:00
|
|
|
|
public class PresenceViewModel : ViewModelBase, IRoutableViewModel
|
|
|
|
|
{
|
|
|
|
|
public string? UrlPathSegment { get; }
|
|
|
|
|
public IScreen HostScreen { get; }
|
2024-12-23 15:12:32 +00:00
|
|
|
|
|
2025-04-21 09:00:17 +00:00
|
|
|
|
public ReactiveCommand<Unit, Unit> GoBackCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> FilterAttendanceCommand { get; }
|
2024-12-23 15:12:32 +00:00
|
|
|
|
|
2025-04-21 09:00:17 +00:00
|
|
|
|
public ObservableCollection<PresencePresenter> AttendanceRecords { get; set; } = new();
|
|
|
|
|
public ObservableCollection<Group> Groups { get; set; } = new();
|
|
|
|
|
public ObservableCollection<string> AttendanceTypes { get; set; } = new()
|
|
|
|
|
{
|
|
|
|
|
"Присутствовал",
|
|
|
|
|
"Отсутствовал",
|
|
|
|
|
};
|
2024-12-23 15:12:32 +00:00
|
|
|
|
|
2025-04-21 09:00:17 +00:00
|
|
|
|
private Group? _selectedGroup;
|
|
|
|
|
public Group? SelectedGroup
|
2024-12-23 15:12:32 +00:00
|
|
|
|
{
|
2025-04-21 09:00:17 +00:00
|
|
|
|
get => _selectedGroup;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.RaiseAndSetIfChanged(ref _selectedGroup, value);
|
|
|
|
|
FilterAttendanceRecords();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime? _selectedDate;
|
|
|
|
|
public DateTime? SelectedDate
|
|
|
|
|
{
|
|
|
|
|
get => _selectedDate;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.RaiseAndSetIfChanged(ref _selectedDate, value);
|
|
|
|
|
FilterAttendanceRecords();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly IGroupUseCase _groupUseCase;
|
|
|
|
|
private readonly IPresenceUseCase _presenceUseCase;
|
|
|
|
|
|
|
|
|
|
public PresenceViewModel(IScreen hostScreen, IGroupUseCase groupUseCase, IPresenceUseCase presenceUseCase)
|
|
|
|
|
{
|
|
|
|
|
HostScreen = hostScreen;
|
|
|
|
|
_groupUseCase = groupUseCase;
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
|
|
|
|
|
|
|
|
|
GoBackCommand = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
|
|
|
|
HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
FilterAttendanceCommand = ReactiveCommand.Create(FilterAttendanceRecords);
|
|
|
|
|
|
|
|
|
|
LoadGroups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadGroups()
|
|
|
|
|
{
|
|
|
|
|
Groups.Clear();
|
|
|
|
|
var groups = _groupUseCase.GetAllGroups();
|
|
|
|
|
foreach (var group in groups)
|
|
|
|
|
{
|
|
|
|
|
Groups.Add(group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FilterAttendanceRecords()
|
|
|
|
|
{
|
|
|
|
|
if (SelectedGroup == null || SelectedDate == null)
|
|
|
|
|
{
|
|
|
|
|
AttendanceRecords.Clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-04 19:33:12 +00:00
|
|
|
|
|
2025-04-21 09:00:17 +00:00
|
|
|
|
var dateOnly = DateOnly.FromDateTime(SelectedDate.Value);
|
|
|
|
|
|
|
|
|
|
var records = _presenceUseCase.GetPresenceByGroupByTime(
|
|
|
|
|
SelectedGroup.ID,
|
|
|
|
|
dateOnly);
|
|
|
|
|
|
|
|
|
|
AttendanceRecords.Clear();
|
|
|
|
|
foreach (var record in records)
|
|
|
|
|
{
|
|
|
|
|
// Преобразуем значение IsAttedance в строку прямо здесь
|
|
|
|
|
var attendanceStatus = record.IsAttedance ? "Был на уроке" : "Не был на уроке";
|
|
|
|
|
|
|
|
|
|
AttendanceRecords.Add(new PresencePresenter
|
|
|
|
|
{
|
|
|
|
|
UserGuid = record.User.Guid,
|
|
|
|
|
IsAttedance = record.IsAttedance, // оставляем bool в модели
|
|
|
|
|
Date = record.Date,
|
|
|
|
|
LessonNumber = record.LessonNumber,
|
|
|
|
|
user = new UserPresenter
|
|
|
|
|
{
|
|
|
|
|
Name = record.User.FIO,
|
|
|
|
|
Guid = record.User.Guid
|
|
|
|
|
},
|
|
|
|
|
AttendanceStatus = attendanceStatus // добавляем строковое представление
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Новый метод для обработки изменения типа посещаемости
|
|
|
|
|
public void OnAttendanceTypeChanged(PresencePresenter presence, string newType)
|
|
|
|
|
{
|
|
|
|
|
presence.IsAttedance = newType == "Присутствовал";
|
|
|
|
|
|
|
|
|
|
if (_presenceUseCase.UpdateAttendance(presence.LessonNumber, presence.Date, presence.UserGuid, presence.IsAttedance))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Изменен тип посещаемости для {presence.user.Name}: {newType}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Не удалось обновить тип посещаемости для {presence.user.Name}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|