83 lines
3.7 KiB
C#
83 lines
3.7 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.Repository;
|
|
using Posechaemost.Domain.Models;
|
|
|
|
namespace Posechaemost.Domain.UseCase
|
|
{
|
|
public class PresenceUseCase
|
|
{
|
|
private readonly PresenceRepositoryImpl _repositoryPresenceImpl;
|
|
private readonly UserRepositoryImpl _repositoryUserImpl;
|
|
private readonly GroupRepositoryImpl _repositoryGroupImpl;
|
|
|
|
public PresenceUseCase(PresenceRepositoryImpl repositoryImpl, UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl) {
|
|
_repositoryPresenceImpl = repositoryImpl;
|
|
_repositoryUserImpl = userRepositoryImpl;
|
|
_repositoryGroupImpl = groupRepositoryImpl;
|
|
}
|
|
|
|
public List<Presence> GetPresenceByGroup(int groupId) {
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
|
|
|
|
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup(groupId)
|
|
.Where(x => users.Any(user => user.Guid == x.UserGuid))
|
|
.Select(presence => new Presence{
|
|
User = new User{
|
|
Guid = presence.UserGuid,
|
|
GroupId = new Group{
|
|
Id = groupId,
|
|
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
|
|
},
|
|
FIO = users.First(user => user.Guid == presence.UserGuid).FIO,
|
|
},
|
|
ClassNumber = presence.ClassNumber,
|
|
Date = presence.Date,
|
|
IsAttendence = presence.IsAttendence
|
|
}).ToList();
|
|
return presenceByGroup;
|
|
}
|
|
|
|
public List<Presence> 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.Guid == x.UserGuid && x.Date == date))
|
|
.Select(presence => new Presence{
|
|
User = new User{
|
|
Guid = presence.UserGuid,
|
|
GroupId = new Group{
|
|
Id = groupId,
|
|
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
|
|
},
|
|
FIO = users.First(user => user.Guid == presence.UserGuid).FIO,
|
|
},
|
|
ClassNumber = presence.ClassNumber,
|
|
Date = presence.Date,
|
|
IsAttendence = presence.IsAttendence
|
|
}).ToList();
|
|
return presenceByGroupAndDate;
|
|
}
|
|
|
|
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid) {
|
|
return _repositoryPresenceImpl.UncheckAttendence(firstClass, lastClass, date, userGuid);
|
|
}
|
|
|
|
public void AddPresence(int firstClass, int lastClass, int groupId,DateOnly date)
|
|
{
|
|
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID==groupId).ToList();
|
|
List<PresenceLocalEntity> presenceList = new List<PresenceLocalEntity>();
|
|
for (int i = firstClass; i < lastClass; i++) {
|
|
foreach (var user in users) {
|
|
PresenceLocalEntity pres = new PresenceLocalEntity {ClassNumber = i, Date = date, UserGuid = user.Guid};
|
|
presenceList.Add(pres);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |