2024-10-28 03:24:11 +00:00
|
|
|
using Demo.Data.LocalData;
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase;
|
2024-10-24 20:41:31 +00:00
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
2024-10-28 03:24:11 +00:00
|
|
|
using Demo.Domain.Models;
|
2024-10-23 19:46:46 +00:00
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
{
|
2024-10-24 20:41:31 +00:00
|
|
|
public class SQLPresenceRepositoryImpl : IPresenceRepository
|
2024-10-23 19:46:46 +00:00
|
|
|
{
|
2024-10-24 20:41:31 +00:00
|
|
|
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>{};
|
2024-10-23 19:46:46 +00:00
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public List<PresenceLocalEntity> GetAllPresences(){
|
2024-10-24 20:41:31 +00:00
|
|
|
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
|
|
|
|
2024-10-24 20:41:31 +00:00
|
|
|
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities)
|
|
|
|
{
|
2024-10-28 03:24:11 +00:00
|
|
|
var presences = presenceLocalEntities.Select(x => new PresenceDAO
|
2024-10-24 20:41:31 +00:00
|
|
|
{
|
|
|
|
UserGuid = x.UserGuid,
|
|
|
|
IsAttedance = x.IsAttedance,
|
|
|
|
LessonNumber = x.LessonNumber,
|
|
|
|
Date = x.Date,
|
2024-10-28 03:24:11 +00:00
|
|
|
userDAO = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid)
|
2024-10-24 20:41:31 +00:00
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
_remoteDatabaseContext.PresenceDaos.AddRange(presences);
|
|
|
|
_remoteDatabaseContext.SaveChanges();
|
|
|
|
|
2024-10-23 19:46:46 +00:00
|
|
|
return presenceLocalEntities;
|
|
|
|
}
|
|
|
|
|
2024-10-28 03:24:11 +00:00
|
|
|
public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
2024-10-24 20:41:31 +00:00
|
|
|
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;
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
2024-10-24 20:41:31 +00:00
|
|
|
|
|
|
|
_remoteDatabaseContext.SaveChanges();
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
2024-10-28 03:24:11 +00:00
|
|
|
|
2024-10-23 19:46:46 +00:00
|
|
|
}
|
2024-10-28 03:24:11 +00:00
|
|
|
}
|