52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AttendanceApp.Data.Repository;
|
|
using AttendanceApp.Domain.Models;
|
|
|
|
namespace AttendanceApp.Domain.UseCases
|
|
{
|
|
public class UseCaseGeneratePresence
|
|
{
|
|
private readonly IPresenceRepository _presenceRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IGroupRepository _groupRepository;
|
|
|
|
public UseCaseGeneratePresence(IPresenceRepository presenceRepository, IUserRepository userRepository, IGroupRepository groupRepository)
|
|
{
|
|
_presenceRepository = presenceRepository;
|
|
_userRepository = userRepository;
|
|
_groupRepository = groupRepository;
|
|
}
|
|
|
|
public void GenerateDailyPresence(int firstClassNumber, int lastClassNumber, int groupId, DateTime date)
|
|
{
|
|
var group = _groupRepository.GetGroupById(groupId);
|
|
var users = _userRepository.GetAllUsers().Where(u => u.GroupId == groupId);
|
|
|
|
foreach (var user in users)
|
|
{
|
|
for (int classNum = firstClassNumber; classNum <= lastClassNumber; classNum++)
|
|
{
|
|
var presence = new Presence
|
|
{
|
|
ClassDate = date.Date,
|
|
ClassNumber = classNum,
|
|
IsPresent = true,
|
|
UserId = user.Id
|
|
};
|
|
_presenceRepository.AddPresence(presence);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void GenerateWeeklyPresence(int firstClassNumber, int lastClassNumber, int groupId, DateTime startDate)
|
|
{
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
var currentDate = startDate.AddDays(i);
|
|
GenerateDailyPresence(firstClassNumber, lastClassNumber, groupId, currentDate);
|
|
}
|
|
}
|
|
}
|
|
} |