pr/Demo/Domain/UseCase/UseCasePresence.cs

56 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-10-25 20:08:16 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Domain.UseCase
{
public class UseCasePresence
{
private Dictionary<string, List<DateTime>> attendanceRecords;
public UseCasePresence()
{
attendanceRecords = new Dictionary<string, List<DateTime>>();
}
public void MarkAttendance(string group, DateTime date)
{
if (!attendanceRecords.ContainsKey(group))
{
attendanceRecords[group] = new List<DateTime>();
}
attendanceRecords[group].Add(date);
}
public List<DateTime> GetAttendanceByGroup(string group)
{
if (attendanceRecords.ContainsKey(group))
{
return attendanceRecords[group];
}
return new List<DateTime>();
}
public List<DateTime> GetAttendanceByGroupAndDate(string group, DateTime date)
{
if (attendanceRecords.ContainsKey(group))
{
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))
{
attendanceRecords[group].Remove(date);
}
}
}
}
}