Raspisanie/Zurnal/Domain/UseCase/UseCasePresence.cs

39 lines
1.3 KiB
C#
Raw Normal View History

2024-10-21 11:56:16 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2024-10-23 08:14:10 +00:00
using Zurnal.Presence
2024-10-21 11:56:16 +00:00
2024-10-21 12:07:01 +00:00
namespace Zurnal.Presence
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
}