71 lines
3.0 KiB
C#
71 lines
3.0 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(PresenceLocalEntity presence) {
|
|
return _repositoryPresenceImpl.UncheckAttendence(presence);
|
|
}
|
|
}
|
|
} |