Raspisanie/Zurnal/Domain/UseCase/UseCasePresence.cs
2024-10-28 11:22:33 +03:00

36 lines
1.3 KiB
C#

using static Zurnal.Presence.UseCaseGeneratePresence;
namespace Zurnal.Domain.UseCase
{
internal class UseCasePresence
{
private List<AttendanceRecord> attendanceRecords;
public UseCasePresence(List<AttendanceRecord> attendanceRecords)
{
this.attendanceRecords = attendanceRecords;
}
public List<AttendanceRecord> GetAttendanceByGroup(string groupNumber)
{
return attendanceRecords.Where(record => record.GroupNumber == groupNumber).ToList();
}
public List<AttendanceRecord> GetAttendanceByGroupAndDate(string groupNumber, DateTime date)
{
return attendanceRecords.Where(record => record.GroupNumber == groupNumber && record.Date.Date == date.Date).ToList();
}
public void MarkUserAsAbsent(string groupNumber, int firstLesson, int lastLesson, DateTime date)
{
foreach (var lesson in Enumerable.Range(firstLesson, lastLesson - firstLesson + 1))
{
var record = attendanceRecords.FirstOrDefault(r => r.GroupNumber == groupNumber && r.LessonNumber == lesson && r.Date.Date == date.Date);
if (record != null)
{
record.IsPresent = false;
}
}
}
}
}