Perepis/domain/UseCase/UseCasePresence.cs

44 lines
1.6 KiB
C#
Raw Normal View History

2024-11-08 08:29:02 +00:00
using Data.RemoteData.DAO;
namespace Data.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;
}
}
}
public void MarkUserAsAbsentForWeek(string groupNumber, int firstLesson, int lastLesson, DateOnly startDate)
{
foreach (var day in Enumerable.Range(0, 7))
{
var date = startDate.AddDays(day);
MarkUserAsAbsent(groupNumber, firstLesson, lastLesson, date);
}
}
}
}