2024-11-01 19:07:13 +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();
|
|
|
|
|
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date){
|
|
|
|
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
|
|
|
.Where(user => user.GroupID == groupID).ToList();
|
|
|
|
|
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
|
|
|
.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-11-11 12:00:01 +00:00
|
|
|
public PresenceResponse GetPresencebyAll(int GroupID, DateOnly? start = null, DateOnly? end = null, Guid userGuid = default){
|
|
|
|
IEnumerable<UserLocalEntity>? users = null;
|
|
|
|
if (userGuid == default)
|
2024-11-11 07:01:04 +00:00
|
|
|
{
|
2024-11-11 12:00:01 +00:00
|
|
|
users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == GroupID);
|
|
|
|
} else {
|
|
|
|
users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == GroupID && x.Guid == userGuid);
|
|
|
|
}
|
|
|
|
var usersFor = new List<UserPresenceInfo>();
|
|
|
|
foreach(var user in users){
|
|
|
|
IEnumerable<PresenceLocalEntity> presences;
|
|
|
|
if (userGuid != default){
|
|
|
|
presences = _repositoryPresenceImpl.GetAllPresences().Where(x => x.UserGuid == userGuid).ToList();
|
|
|
|
}else{
|
|
|
|
presences = _repositoryPresenceImpl.GetAllPresences().ToList();
|
|
|
|
}
|
|
|
|
foreach(var presence in presences)
|
|
|
|
{
|
|
|
|
if (start.HasValue && end.HasValue)
|
|
|
|
{
|
|
|
|
if (presence.Date >= start && presence.Date <= end)
|
|
|
|
{
|
|
|
|
usersFor.Add(new UserPresenceInfo{
|
|
|
|
FIO = user.FIO, LessonNumber = presence.LessonNumber, Date = presence.Date, IsAttendance = presence.IsAttedance
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
usersFor.Add(new UserPresenceInfo{
|
|
|
|
FIO = user.FIO, LessonNumber = presence.LessonNumber, Date = presence.Date, IsAttendance = presence.IsAttedance
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var presenceGet = new PresenceResponse{
|
|
|
|
GroupName = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(x => x.ID == GroupID).Name,
|
|
|
|
Users = usersFor
|
2024-11-11 07:01:04 +00:00
|
|
|
};
|
2024-11-11 12:00:01 +00:00
|
|
|
return presenceGet;
|
2024-11-11 07:01:04 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 19:07:13 +00:00
|
|
|
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
|
|
|
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
IsAttedance = true,
|
|
|
|
Date = date,
|
|
|
|
LessonNumber = i
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity
|
|
|
|
{
|
|
|
|
UserGuid = x.User.Guid,
|
|
|
|
IsAttedance = x.IsAttedance,
|
|
|
|
LessonNumber = x.LessonNumber,
|
|
|
|
Date = x.Date
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
_repositoryPresenceImpl.GeneratePresence(presenceLocalEntity);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-11-08 17:42:34 +00:00
|
|
|
public bool DeletePresence(){
|
|
|
|
return _repositoryPresenceImpl.DeletePresence();
|
|
|
|
}
|
|
|
|
|
2024-11-11 12:00:01 +00:00
|
|
|
public bool DeletePresenceByUser(Guid userGuid) {
|
|
|
|
return _repositoryPresenceImpl.DeletePresenceByUserGuid(userGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DeletePresenceByGroup(int groupID) {
|
|
|
|
return _repositoryPresenceImpl.DeletePresenceByGroup(groupID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DeletePresenceByDateRange(DateOnly startDate, DateOnly endDate) {
|
|
|
|
return _repositoryPresenceImpl.DeletePresenceByDateRange(startDate, endDate);
|
|
|
|
}
|
|
|
|
|
2024-11-01 19:07:13 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|