2024-10-28 03:24:11 +00:00
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2024-10-23 19:46:46 +00:00
|
|
|
using Demo.Data.Repository;
|
2024-10-28 03:24:11 +00:00
|
|
|
using Demo.Domain.Models;
|
2024-10-23 19:46:46 +00:00
|
|
|
|
|
|
|
namespace Demo.Domain.UseCase
|
|
|
|
{
|
|
|
|
public class PresenceUseCase : IPresenceUseCase
|
|
|
|
{
|
2024-10-28 03:24:11 +00:00
|
|
|
private readonly IUserRepository _repositoryUserImpl;
|
2024-10-23 19:46:46 +00:00
|
|
|
private readonly IPresenceRepository _repositoryPresenceImpl;
|
|
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl)
|
2024-10-23 19:46:46 +00:00
|
|
|
{
|
2024-10-28 03:24:11 +00:00
|
|
|
_repositoryPresenceImpl = repositoryPresenceImpl;
|
2024-10-23 19:46:46 +00:00
|
|
|
_repositoryUserImpl = repositoryUserImpl;
|
2024-10-28 03:24:11 +00:00
|
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public List<Presence> GetPresenceByGroup(int groupID){
|
2024-10-23 19:46:46 +00:00
|
|
|
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
2024-10-28 03:24:11 +00:00
|
|
|
.Where(user => user.GroupID == groupID).ToList();
|
2024-10-23 19:46:46 +00:00
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
2024-10-23 19:46:46 +00:00
|
|
|
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid))
|
|
|
|
.Select(presence => new Presence{
|
|
|
|
User = new User{
|
|
|
|
Guid = presence.UserGuid,
|
|
|
|
Group = new Group{
|
2024-10-28 03:24:11 +00:00
|
|
|
ID = groupID,
|
|
|
|
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
|
2024-10-23 19:46:46 +00:00
|
|
|
},
|
|
|
|
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
|
|
|
|
},
|
|
|
|
LessonNumber = presence.LessonNumber,
|
|
|
|
Date = presence.Date,
|
|
|
|
IsAttedance = presence.IsAttedance
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
return presenceByGroup;
|
|
|
|
}
|
2024-10-28 03:24:11 +00:00
|
|
|
|
|
|
|
public List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date){
|
2024-10-23 19:46:46 +00:00
|
|
|
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
2024-10-28 03:24:11 +00:00
|
|
|
.Where(user => user.GroupID == groupID).ToList();
|
2024-10-23 19:46:46 +00:00
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
2024-10-23 19:46:46 +00:00
|
|
|
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date))
|
|
|
|
.Select(presence => new Presence{
|
|
|
|
User = new User{
|
|
|
|
Guid = presence.UserGuid,
|
|
|
|
Group = new Group{
|
2024-10-28 03:24:11 +00:00
|
|
|
ID = groupID,
|
|
|
|
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
|
2024-10-23 19:46:46 +00:00
|
|
|
},
|
|
|
|
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
|
|
|
|
},
|
|
|
|
LessonNumber = presence.LessonNumber,
|
|
|
|
Date = presence.Date,
|
|
|
|
IsAttedance = presence.IsAttedance
|
|
|
|
}).ToList();
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
return presenceByGroup;
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
|
|
|
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
|
2024-10-23 19:46:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date)
|
|
|
|
{
|
|
|
|
var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupID).ToList();
|
|
|
|
var groupName = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name;
|
|
|
|
|
|
|
|
List<Presence> presenceList = new List<Presence>();
|
|
|
|
|
|
|
|
for (int i = firstLesson; i <= lastLesson; i++)
|
|
|
|
{
|
|
|
|
foreach (UserLocalEntity user in usersByGroup)
|
|
|
|
{
|
|
|
|
presenceList.Add(new Presence
|
|
|
|
{
|
|
|
|
User = new User
|
|
|
|
{
|
|
|
|
Group = new Group
|
|
|
|
{
|
|
|
|
ID = groupID,
|
|
|
|
Name = groupName
|
|
|
|
},
|
|
|
|
FIO = user.FIO,
|
|
|
|
Guid = user.Guid
|
2024-10-23 19:46:46 +00:00
|
|
|
},
|
2024-10-28 03:24:11 +00:00
|
|
|
IsAttedance = true,
|
|
|
|
Date = date,
|
|
|
|
LessonNumber = i
|
|
|
|
});
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity
|
|
|
|
{
|
2024-10-23 19:46:46 +00:00
|
|
|
UserGuid = x.User.Guid,
|
|
|
|
IsAttedance = x.IsAttedance,
|
|
|
|
LessonNumber = x.LessonNumber,
|
|
|
|
Date = x.Date
|
|
|
|
}).ToList();
|
|
|
|
|
2024-10-24 20:41:31 +00:00
|
|
|
_repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
|
2024-10-23 19:46:46 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
2024-10-23 19:46:46 +00:00
|
|
|
for (int i = 0; i < 8; i++){
|
2024-10-28 03:24:11 +00:00
|
|
|
GeneratePresence(firstLesson, lastLesson, groupID, date.AddDays(i));
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|