2024-10-28 08:22:33 +00:00
|
|
|
|
using static Zurnal.Presence.UseCaseGeneratePresence;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-10-23 08:27:57 +00:00
|
|
|
|
namespace Zurnal.Domain.UseCase
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
|
|
|
|
internal class UseCasePresence
|
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
private List<AttendanceRecord> attendanceRecords;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-10-21 12:07:01 +00:00
|
|
|
|
public UseCasePresence(List<AttendanceRecord> attendanceRecords)
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
this.attendanceRecords = attendanceRecords;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 12:07:01 +00:00
|
|
|
|
public List<AttendanceRecord> GetAttendanceByGroup(string groupNumber)
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
return attendanceRecords.Where(record => record.GroupNumber == groupNumber).ToList();
|
2024-10-21 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 12:07:01 +00:00
|
|
|
|
public List<AttendanceRecord> GetAttendanceByGroupAndDate(string groupNumber, DateTime date)
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
return attendanceRecords.Where(record => record.GroupNumber == groupNumber && record.Date.Date == date.Date).ToList();
|
2024-10-21 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 12:07:01 +00:00
|
|
|
|
public void MarkUserAsAbsent(string groupNumber, int firstLesson, int lastLesson, DateTime date)
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
foreach (var lesson in Enumerable.Range(firstLesson, lastLesson - firstLesson + 1))
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
var record = attendanceRecords.FirstOrDefault(r => r.GroupNumber == groupNumber && r.LessonNumber == lesson && r.Date.Date == date.Date);
|
|
|
|
|
if (record != null)
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-21 12:07:01 +00:00
|
|
|
|
record.IsPresent = false;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-21 12:07:01 +00:00
|
|
|
|
}
|