Raspisanie/Zurnal/Domain/UseCase/UseCasePresence.cs
2024-11-11 11:31:26 +03:00

37 lines
1.3 KiB
C#

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