2024-10-21 22:57:01 +00:00
|
|
|
|
using Demo.Data.Repository;
|
2024-10-23 09:52:43 +00:00
|
|
|
|
using Demo.Domain.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-10-21 22:57:01 +00:00
|
|
|
|
|
|
|
|
|
namespace Demo.Domain.UseCases
|
|
|
|
|
{
|
|
|
|
|
public class GroupUseCase
|
|
|
|
|
{
|
2024-10-23 09:52:43 +00:00
|
|
|
|
private readonly IPresenceRepository _presenceRepository;
|
|
|
|
|
private readonly GroupRepositoryImpl _groupRepository; // Измените на GroupRepositoryImpl
|
2024-10-21 22:57:01 +00:00
|
|
|
|
|
2024-10-23 09:52:43 +00:00
|
|
|
|
public GroupUseCase(GroupRepositoryImpl groupRepository, IPresenceRepository presenceRepository) // Конструктор
|
2024-10-21 22:57:01 +00:00
|
|
|
|
{
|
|
|
|
|
_groupRepository = groupRepository;
|
2024-10-23 09:52:43 +00:00
|
|
|
|
_presenceRepository = presenceRepository;
|
2024-10-21 22:57:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 09:52:43 +00:00
|
|
|
|
// Метод для генерации посещаемости на текущий день
|
|
|
|
|
public List<LessonPresence> GeneratePresence(int firstLessonNumber, int lastLessonNumber, int groupId, DateTime currentDate)
|
|
|
|
|
{
|
|
|
|
|
var users = _groupRepository.GetUsersByGroup(groupId); // Получаем пользователей группы
|
|
|
|
|
List<LessonPresence> presenceList = new List<LessonPresence>();
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
var lessons = new List<bool>(new bool[lastLessonNumber - firstLessonNumber + 1]); // По умолчанию все посещены
|
|
|
|
|
var presence = new LessonPresence(user.Id, currentDate, groupId, lessons); // Измените на LessonPresence
|
|
|
|
|
presenceList.Add(presence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return presenceList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для генерации посещаемости на неделю
|
|
|
|
|
public Dictionary<DateTime, List<LessonPresence>> GenerateWeeklyPresence(int firstLessonNumber, int lastLessonNumber, int groupId, DateTime startDate)
|
|
|
|
|
{
|
|
|
|
|
var weeklyPresence = new Dictionary<DateTime, List<LessonPresence>>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
var currentDate = startDate.AddDays(i);
|
|
|
|
|
var dailyPresence = GeneratePresence(firstLessonNumber, lastLessonNumber, groupId, currentDate);
|
|
|
|
|
weeklyPresence[currentDate] = dailyPresence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return weeklyPresence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для вывода посещаемости по группе
|
|
|
|
|
public List<LessonPresence> GetPresenceByGroup(int groupId)
|
|
|
|
|
{
|
|
|
|
|
return _presenceRepository.GetPresenceByGroup(groupId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для вывода посещаемости по группе по дате
|
|
|
|
|
public List<LessonPresence> GetPresenceByGroupAndDate(int groupId, DateTime date)
|
|
|
|
|
{
|
|
|
|
|
return _presenceRepository.GetPresenceByGroupAndDate(groupId, date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для отметки пользователя как отсутствующего
|
|
|
|
|
public void MarkUserAbsent(Guid userId, int groupId, DateTime date, List<int> lessonNumbers)
|
|
|
|
|
{
|
|
|
|
|
var presenceRecords = _presenceRepository.GetPresenceByGroupAndDate(groupId, date);
|
|
|
|
|
|
|
|
|
|
var presenceRecord = presenceRecords.FirstOrDefault(p => p.UserId == userId);
|
|
|
|
|
if (presenceRecord != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var lessonNumber in lessonNumbers)
|
|
|
|
|
{
|
|
|
|
|
if (lessonNumber >= 0 && lessonNumber < presenceRecord.Lessons.Count)
|
|
|
|
|
{
|
|
|
|
|
presenceRecord.Lessons[lessonNumber] = false; // Отмечаем как отсутствующего
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_presenceRepository.UpdatePresence(presenceRecord); // Обновляем запись в репозитории
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-21 22:57:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|