83 lines
3.5 KiB
C#
83 lines
3.5 KiB
C#
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;
|
|
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Posechaemost.Data.Repository;
|
|
using Posechaemost.Domain.Models;
|
|
|
|
namespace Posechaemost.Domain.UseCase
|
|
{
|
|
public class PresenceUseCase
|
|
{
|
|
private readonly SQLPresenceRepositoryImpl _repositoryPresenceImpl;
|
|
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
|
|
private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
|
|
|
|
public PresenceUseCase(SQLPresenceRepositoryImpl repositoryImpl,
|
|
SQLUserRepositoryImpl userRepositoryImpl,
|
|
SQLGroupRepositoryImpl groupRepositoryImpl) {
|
|
_repositoryPresenceImpl = repositoryImpl;
|
|
_repositoryUserImpl = userRepositoryImpl;
|
|
_repositoryGroupImpl = groupRepositoryImpl;
|
|
}
|
|
|
|
public List<PresenceDao> GetPresenceByGroup(int groupId) {
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
|
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup(groupId)
|
|
.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;
|
|
}
|
|
|
|
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date) {
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
|
|
|
|
var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresenceByGroupAndDate(groupId, date)
|
|
.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;
|
|
}
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|