66 lines
2.8 KiB
C#
66 lines
2.8 KiB
C#
using Data.RemoteData.RemoteDataBase.DAO;
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Demo.domain.Models;
|
|
|
|
namespace Demo.Data.Repository
|
|
{
|
|
public class SQLPresenceRepositoryImpl : IPresenceRepository
|
|
{
|
|
|
|
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
|
|
|
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){
|
|
_remoteDatabaseContext = remoteDatabaseContext;
|
|
GetAllPresence = _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
|
}
|
|
|
|
public List<PresenceLocalEntity> GetAllPresence = new List<PresenceLocalEntity>{};
|
|
|
|
public List<PresenceLocalEntity> GetPresences()
|
|
{
|
|
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
|
}
|
|
|
|
public List<PresenceLocalEntity> GetPresencesByGroup()
|
|
{
|
|
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
|
}
|
|
|
|
public List<PresenceLocalEntity> GetPresencesByGroupAndDate()
|
|
{
|
|
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
|
}
|
|
|
|
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities)
|
|
{
|
|
var presences = presenceLocalEntities.Select(x => new PresenceDao
|
|
{
|
|
UserGuid = x.UserGuid,
|
|
IsAttedance = x.IsAttedance,
|
|
LessonNumber = x.LessonNumber,
|
|
Date = x.Date,
|
|
userDao = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid)
|
|
}).ToList();
|
|
|
|
_remoteDatabaseContext.PresenceDaos.AddRange(presences);
|
|
_remoteDatabaseContext.SaveChanges();
|
|
|
|
return presenceLocalEntities;
|
|
}
|
|
|
|
public void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
|
var presencesToUpdate = _remoteDatabaseContext.PresenceDaos
|
|
.Where(x => x.LessonNumber >= firstLesson
|
|
&& x.LessonNumber <= lastLesson
|
|
&& x.Date == date
|
|
&& x.UserGuid == UserGuid)
|
|
.ToList();
|
|
|
|
foreach(var presence in presencesToUpdate){
|
|
presence.IsAttedance = false;
|
|
}
|
|
|
|
_remoteDatabaseContext.SaveChanges();
|
|
}
|
|
}
|
|
} |