Demo/Domain/UseCase/PresenceUseCase.cs

83 lines
3.5 KiB
C#
Raw Normal View History

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;
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-11-06 04:10:09 +00:00
public PresenceUseCase(SQLPresenceRepositoryImpl repositoryImpl,
SQLUserRepositoryImpl userRepositoryImpl,
SQLGroupRepositoryImpl groupRepositoryImpl) {
_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();
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,
},
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();
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,
},
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);
}
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};
presenceList.Add(pres);
}
}
}
}
2024-11-06 04:10:09 +00:00
}