2024-11-25 04:33:26 +00:00
|
|
|
|
using Demo.Data.Repository;
|
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
using Demo.Domain.Models;
|
2024-10-28 12:42:04 +00:00
|
|
|
|
using System;
|
2024-10-24 08:50:32 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-10-28 12:42:04 +00:00
|
|
|
|
namespace Demo.Domain.UseCase
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
|
|
|
|
public class UseCaseGeneratePresence
|
|
|
|
|
{
|
|
|
|
|
private readonly IPresenceRepository _presenceRepository;
|
|
|
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
|
|
2024-10-28 12:42:04 +00:00
|
|
|
|
public UseCaseGeneratePresence(IPresenceRepository presenceRepository, IUserRepository userRepository)
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
_presenceRepository = presenceRepository ?? throw new ArgumentNullException(nameof(presenceRepository));
|
|
|
|
|
_userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
|
2024-10-24 08:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public void GeneratePresenceForToday(int firstLesson, int lastLesson, int groupId, DateTime date)
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
|
|
|
|
|
var users = _userRepository.GetAllUsers().Where(u => u.GroupID == groupId);
|
2024-10-24 08:50:32 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
2024-10-28 12:42:04 +00:00
|
|
|
|
for (int lesson = firstLesson; lesson <= lastLesson; lesson++)
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
var daoPresence = new Demo.Data.RemoteData.RemoteDataBase.DAO.Presence
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
Date = date,
|
|
|
|
|
LessonNumber = lesson,
|
|
|
|
|
IsAttendance = true,
|
|
|
|
|
UserId = user.Id
|
|
|
|
|
};
|
2024-10-28 12:42:04 +00:00
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
var domainPresence = new Demo.Domain.Models.Presence
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
Id = daoPresence.Id,
|
|
|
|
|
Date = daoPresence.Date,
|
|
|
|
|
LessonNumber = daoPresence.LessonNumber,
|
|
|
|
|
IsAttendance = daoPresence.IsAttendance,
|
|
|
|
|
UserId = daoPresence.UserId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_presenceRepository.AddPresence(domainPresence);
|
2024-10-24 08:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public void GeneratePresenceForWeek(int firstLesson, int lastLesson, int groupId, DateTime startDate)
|
2024-10-24 08:50:32 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
startDate = DateTime.SpecifyKind(startDate, DateTimeKind.Utc);
|
2024-10-24 08:50:32 +00:00
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
GeneratePresenceForToday(firstLesson, lastLesson, groupId, startDate.AddDays(i));
|
2024-10-24 08:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|