presence/Domain/UseCase/UseCaseGeneratePresence.cs

68 lines
2.4 KiB
C#
Raw Normal View History

2024-12-06 08:51:13 +00:00
using presence.Data.LocalData.Entity;
using presence.Data.ReportsHistory;
using presence.Data.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace presence.Domain.UseCase
{
public class UseCaseGeneratePresence
{
private readonly PresenceRepositoryImpl _presenceRepositoryImpl;
private readonly GroupRepositoryImpl _groupRepositoryImpl;
private readonly UserRepositoryImpl _userRepositoryImpl;
public UseCaseGeneratePresence(PresenceRepositoryImpl repositoryImpl,
UserRepositoryImpl userRepositoryImpl,
GroupRepositoryImpl groupRepositoryImpl)
{
_presenceRepositoryImpl = repositoryImpl;
_userRepositoryImpl = userRepositoryImpl;
_groupRepositoryImpl = groupRepositoryImpl;
}
public void AddPrecence(int firstClass, int lastClass, int groupId, DateOnly date)
{
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
List<PresenceLocalEntity> presence = new List<PresenceLocalEntity>();
for (int i = firstClass; i < lastClass; i++)
{
foreach (var user in users)
{
PresenceLocalEntity pres = new PresenceLocalEntity { LessonNumber = i, UserID = user.UserID, Date = date };
}
}
}
public void AddPresenceForWeek(int firstClass, int lastClass, int groupId, DateOnly startDate)
{
var users = _userRepositoryImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
List<PresenceLocalEntity> presence = new List<PresenceLocalEntity>();
for (int dayOffset = 0; dayOffset < 7; dayOffset++)
{
DateOnly date = startDate.AddDays(dayOffset);
for (int i = firstClass; i < lastClass; i++)
{
foreach (var user in users)
{
PresenceLocalEntity pres = new PresenceLocalEntity
{
LessonNumber = i,
UserID = user.UserID,
Date = date
};
presence.Add(pres);
}
}
}
}
}
}