slarny4/Demo1/Domain/UseCase/PresenceUseCase.cs
Class_Student aa3336ca1b init
2024-10-23 12:52:43 +03:00

48 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Demo.Data.Repository;
using Demo.Domain.Models;
namespace Demo.Domain.UseCases
{
public class PresenceUseCase
{
private readonly IPresenceRepository _presenceRepository;
public PresenceUseCase(IPresenceRepository presenceRepository) // Конструктор
{
_presenceRepository = presenceRepository;
}
public void GeneratePresence(int groupNumber, DateTime date)
{
var users = _presenceRepository.GetUsersByGroup(groupNumber);
var presenceList = new List<LessonPresence>();
foreach (var user in users)
{
// Создаем список посещаемости, по умолчанию все отмечены как присутствующие
var lessons = new List<bool> { true, true, true }; // Пример, 3 занятия
presenceList.Add(new LessonPresence(user.UserId, date, groupNumber, lessons));
}
_presenceRepository.SavePresence(presenceList);
}
public List<LessonPresence> GetPresenceByGroup(int groupNumber)
{
return _presenceRepository.GetPresenceByGroup(groupNumber);
}
public List<LessonPresence> GetPresenceByGroupAndDate(int groupNumber, DateTime date)
{
return _presenceRepository.GetPresenceByGroupAndDate(groupNumber, date);
}
public void MarkUserAbsent(Guid userId, int groupNumber, int lessonId, DateTime date)
{
_presenceRepository.MarkUserAbsent(userId, groupNumber, lessonId, date);
}
}
}