Demo/Domain/UseCase/PresenceUseCase.cs

188 lines
7.5 KiB
C#
Raw Permalink Normal View History

2024-10-22 18:51:54 +00:00
using System.Security.Cryptography.X509Certificates;
using Demo.Data.Repository;
using Demo.Domain.Models;
namespace Demo.Domain.UseCase
{
public class PresenceUseCase : IPresenceUseCase
{
private readonly IUserRepository _repositoryUserImpl;
private readonly IPresenceRepository _repositoryPresenceImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl)
{
_repositoryPresenceImpl = repositoryPresenceImpl;
_repositoryUserImpl = repositoryUserImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
public List<Presence> GetPresenceByGroup(int groupID){
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
2024-10-25 21:07:09 +00:00
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
2024-10-22 18:51:54 +00:00
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid))
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
Group = new Group{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByGroup;
}
2024-10-28 10:39:15 +00:00
public List<Presence> GetFalsePresenceByGroup(int groupID){
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid) && x.IsAttedance == false)
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
Group = new Group{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByGroup;
}
public List<Presence> GetPresenceByUser(Guid userGuid){
var user = _repositoryUserImpl.GetUserByGuid(userGuid);
var presenceByUser = _repositoryPresenceImpl.GetAllPresences()
.Where(user => userGuid == user.UserGuid)
.Select(presence => new Presence{
User = new User{
Guid = user.Guid,
Group = new Group{
ID = user.GroupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == user.GroupID).Name
},
FIO = user.FIO
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByUser;
}
public List<Presence> GetFalsePresenceByUser(Guid userGuid){
var user = _repositoryUserImpl.GetUserByGuid(userGuid);
var presenceByUser = _repositoryPresenceImpl.GetAllPresences()
.Where(user => userGuid == user.UserGuid && user.IsAttedance == false)
.Select(presence => new Presence{
User = new User{
Guid = user.Guid,
Group = new Group{
ID = user.GroupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == user.GroupID).Name
},
FIO = user.FIO
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByUser;
}
2024-10-22 18:51:54 +00:00
public List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date){
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
2024-10-25 21:07:09 +00:00
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
2024-10-22 18:51:54 +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{
ID = groupID,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
},
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
},
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttedance = presence.IsAttedance
}).ToList();
return presenceByGroup;
}
2024-10-23 07:53:19 +00:00
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
return true;
}
2024-10-24 15:57:52 +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-22 18:51:54 +00:00
},
2024-10-24 15:57:52 +00:00
IsAttedance = true,
Date = date,
LessonNumber = i
});
2024-10-22 18:51:54 +00:00
}
}
2024-10-24 15:57:52 +00:00
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity
{
2024-10-22 18:51:54 +00:00
UserGuid = x.User.Guid,
IsAttedance = x.IsAttedance,
LessonNumber = x.LessonNumber,
Date = x.Date
}).ToList();
_repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
return true;
}
2024-10-23 09:14:11 +00:00
public bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
for (int i = 0; i < 8; i++){
GeneratePresence(firstLesson, lastLesson, groupID, date.AddDays(i));
}
return true;
}
2024-10-22 18:51:54 +00:00
}
}