This commit is contained in:
Userok 2024-10-21 15:07:01 +03:00
parent 60195b921a
commit fdfa48d9b9
2 changed files with 14 additions and 32 deletions

Binary file not shown.

View File

@ -1,54 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Zurnal.Domain.UseCase
namespace Zurnal.Presence
{
internal class UseCasePresence
{
private Dictionary<string, List<DateTime>> attendanceRecords;
private List<AttendanceRecord> attendanceRecords;
public UseCasePresence()
public UseCasePresence(List<AttendanceRecord> attendanceRecords)
{
attendanceRecords = new Dictionary<string, List<DateTime>>();
this.attendanceRecords = attendanceRecords;
}
public void MarkAttendance(string group, DateTime date)
public List<AttendanceRecord> GetAttendanceByGroup(string groupNumber)
{
if (!attendanceRecords.ContainsKey(group))
{
attendanceRecords[group] = new List<DateTime>();
}
attendanceRecords[group].Add(date);
return attendanceRecords.Where(record => record.GroupNumber == groupNumber).ToList();
}
public List<DateTime> GetAttendanceByGroup(string group)
public List<AttendanceRecord> GetAttendanceByGroupAndDate(string groupNumber, DateTime date)
{
if (attendanceRecords.ContainsKey(group))
{
return attendanceRecords[group];
}
return new List<DateTime>();
return attendanceRecords.Where(record => record.GroupNumber == groupNumber && record.Date.Date == date.Date).ToList();
}
public List<DateTime> GetAttendanceByGroupAndDate(string group, DateTime date)
public void MarkUserAsAbsent(string groupNumber, int firstLesson, int lastLesson, DateTime date)
{
if (attendanceRecords.ContainsKey(group))
foreach (var lesson in Enumerable.Range(firstLesson, lastLesson - firstLesson + 1))
{
return attendanceRecords[group].Where(d => d.Date == date.Date).ToList();
}
return new List<DateTime>();
}
public void MarkUserAsAbsent(string group, DateTime startDate, DateTime endDate)
{
if (attendanceRecords.ContainsKey(group))
{
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
var record = attendanceRecords.FirstOrDefault(r => r.GroupNumber == groupNumber && r.LessonNumber == lesson && r.Date.Date == date.Date);
if (record != null)
{
attendanceRecords[group].Remove(date);
record.IsPresent = false;
}
}
}