2024-10-25 08:39:18 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Posechaemost.Data.LocalData.Entity;
|
2024-11-06 04:10:09 +00:00
|
|
|
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
|
2024-10-25 08:39:18 +00:00
|
|
|
using Posechaemost.Data.Repository;
|
|
|
|
using Posechaemost.Domain.Models;
|
|
|
|
|
|
|
|
namespace Posechaemost.Domain.UseCase
|
|
|
|
{
|
|
|
|
public class PresenceUseCase
|
|
|
|
{
|
2024-11-06 04:10:09 +00:00
|
|
|
private readonly SQLPresenceRepositoryImpl _repositoryPresenceImpl;
|
|
|
|
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
|
|
|
|
private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
|
2024-10-25 08:39:18 +00:00
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public PresenceUseCase(SQLPresenceRepositoryImpl repositoryImpl,
|
|
|
|
SQLUserRepositoryImpl userRepositoryImpl,
|
|
|
|
SQLGroupRepositoryImpl groupRepositoryImpl) {
|
2024-10-25 08:39:18 +00:00
|
|
|
_repositoryPresenceImpl = repositoryImpl;
|
|
|
|
_repositoryUserImpl = userRepositoryImpl;
|
|
|
|
_repositoryGroupImpl = groupRepositoryImpl;
|
|
|
|
}
|
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public List<PresenceDao> GetPresenceByGroup(int groupId) {
|
|
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
|
2024-10-25 08:39:18 +00:00
|
|
|
|
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup(groupId)
|
2024-11-06 04:10:09 +00:00
|
|
|
.Where(x => users.Any(user => user.UserId == x.UserId))
|
|
|
|
.Select(presence => new PresenceDao{
|
|
|
|
User = new UserDao{
|
|
|
|
UserId = presence.UserId,
|
|
|
|
GroupId = groupId,
|
|
|
|
FIO = users.First(user => user.UserId == presence.UserId).FIO,
|
2024-10-25 08:39:18 +00:00
|
|
|
},
|
|
|
|
ClassNumber = presence.ClassNumber,
|
|
|
|
Date = presence.Date,
|
|
|
|
IsAttendence = presence.IsAttendence
|
|
|
|
}).ToList();
|
|
|
|
return presenceByGroup;
|
|
|
|
}
|
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date) {
|
|
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
|
2024-10-25 08:39:18 +00:00
|
|
|
|
|
|
|
var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresenceByGroupAndDate(groupId, date)
|
2024-11-06 04:10:09 +00:00
|
|
|
.Where(x => users.Any(user => user.UserId == x.UserId && x.Date == date))
|
|
|
|
.Select(presence => new PresenceDao{
|
|
|
|
User = new UserDao{
|
|
|
|
UserId = presence.UserId,
|
|
|
|
GroupId = groupId,
|
|
|
|
FIO = users.First(user => user.UserId == presence.UserId).FIO,
|
2024-10-25 08:39:18 +00:00
|
|
|
},
|
|
|
|
ClassNumber = presence.ClassNumber,
|
|
|
|
Date = presence.Date,
|
|
|
|
IsAttendence = presence.IsAttendence
|
|
|
|
}).ToList();
|
|
|
|
return presenceByGroupAndDate;
|
|
|
|
}
|
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) {
|
|
|
|
return _repositoryPresenceImpl.UncheckAttendence(firstClass, lastClass, date, userId);
|
2024-10-28 08:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddPresence(int firstClass, int lastClass, int groupId,DateOnly date)
|
|
|
|
{
|
2024-11-06 04:10:09 +00:00
|
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId==groupId).ToList();
|
|
|
|
List<PresenceDao> presenceList = new List<PresenceDao>();
|
|
|
|
for (int i = firstClass; i < lastClass; i++)
|
|
|
|
{
|
|
|
|
foreach (var user in users)
|
|
|
|
{
|
|
|
|
PresenceDao pres = new PresenceDao{ClassNumber = i, Date = date, UserId = user.UserId, User = user};
|
2024-10-28 08:32:57 +00:00
|
|
|
presenceList.Add(pres);
|
|
|
|
}
|
|
|
|
}
|
2024-10-25 08:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-06 04:10:09 +00:00
|
|
|
}
|