Files
2026-09-25 22:02:00 +02:00

34 lines
1.3 KiB
C#

using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
namespace LehrerApp.Desktop.Services;
/// <summary>Schließt nicht nachgereichte Hausaufgaben 14 Kalendertage nach der Unterrichtsstunde.
/// Nur noch offene Nachreichungen werden geändert; andere Stati und archivierte Gruppen bleiben
/// unangetastet.</summary>
public sealed class HomeworkOverdueService(
IGroupRepository groups, IParticipationSessionRepository sessions,
IParticipationRepository participation)
{
public const int GracePeriodDays = 14;
public int Advance(DateOnly today)
{
var cutoff = today.AddDays(-GracePeriodDays);
var activeGroupIds = groups.GetAll().Where(g => g.IsActive).Select(g => g.Id).ToHashSet();
var changed = 0;
foreach (var session in sessions.GetAll()
.Where(s => s.Date <= cutoff && activeGroupIds.Contains(s.GroupId)))
foreach (var entry in participation.GetBySession(session.Id))
{
if (entry.Homework != HomeworkStatus.MissingOpen &&
!(entry.Homework is null && entry.HomeworkMissing)) continue;
entry.Homework = HomeworkStatus.MissingOverdue;
entry.HomeworkMissing = true;
participation.Save(entry);
changed++;
}
return changed;
}
}