Raspisanie/Presence/UseCaseGeneratePresence.cs

61 lines
2.0 KiB
C#
Raw Normal View History

2024-12-11 08:30:05 +00:00
using data.RemoteData.RemoteDataBase.DAO;
namespace Zurnal.Presence
2024-10-21 11:56:16 +00:00
{
internal class UseCaseGeneratePresence
{
2024-10-23 08:14:10 +00:00
internal class AttendanceRecord
2024-11-11 08:31:26 +00:00
{
public int LessonNumber { get; set; }
public required string GroupNumber { get; set; }
public DateTime Date { get; set; }
public bool IsPresent { get; set; }
}
2024-12-11 08:30:05 +00:00
private List<GroupDao> groups;
public UseCaseGeneratePresence(List<GroupDao> groups)
{
this.groups = groups;
}
2024-10-21 11:56:16 +00:00
public List<AttendanceRecord> GenerateDailyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime currentDate)
{
List<AttendanceRecord> attendanceRecords = new List<AttendanceRecord>();
2024-12-11 08:30:05 +00:00
var group = groups.FirstOrDefault(g => g.Name == groupNumber);
2024-10-21 11:56:16 +00:00
2024-12-11 08:30:05 +00:00
if (group != null)
2024-10-21 11:56:16 +00:00
{
2024-12-11 08:30:05 +00:00
var users = group.Users;
foreach (var user in users)
2024-10-21 11:56:16 +00:00
{
2024-12-11 08:30:05 +00:00
for (int lesson = firstLesson; lesson <= lastLesson; lesson++)
2024-11-11 08:31:26 +00:00
{
2024-12-11 08:30:05 +00:00
attendanceRecords.Add(new AttendanceRecord
{
LessonNumber = lesson,
GroupNumber = groupNumber,
Date = currentDate,
IsPresent = true
});
}
2024-11-11 08:31:26 +00:00
}
2024-10-21 11:56:16 +00:00
}
return attendanceRecords;
}
public List<AttendanceRecord> GenerateWeeklyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime startDate)
{
List<AttendanceRecord> weeklyAttendanceRecords = new List<AttendanceRecord>();
for (int day = 0; day < 7; day++)
{
DateTime currentDate = startDate.AddDays(day);
weeklyAttendanceRecords.AddRange(GenerateDailyAttendance(firstLesson, lastLesson, groupNumber, currentDate));
}
return weeklyAttendanceRecords;
}
}
2024-11-11 08:31:26 +00:00
}