presence123/Demo/Data/Repository/SQLPresenceRepository.cs

70 lines
2.3 KiB
C#
Raw Normal View History

2024-10-25 08:47:11 +00:00
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public class SQLPresenceRepositoryImpl : IPresenceRepository
{
private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public List<PresenceLocalEntity> GetPresenceByDateAndGroup(DateTime date, int groupId)
{
throw new NotImplementedException();
}
public List<PresenceDao> GetPresenceByDateAndGroupDao(DateTime date, int groupId)
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.Date == DateOnly.FromDateTime(date) &&
LocalStaticData.users.Any(u => u.GroupID == groupId && u.ID == p.UserId)).ToList();
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{
throw new NotImplementedException();
}
// Реализация метода для получения всех данных по группе
public List<PresenceDao> GetPresenceByGroupDao(int groupId)
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == groupId).ToList();
}
public void SavePresence(List<PresenceLocalEntity> presences)
{
throw new NotImplementedException();
}
public void SavePresenceDao(List<PresenceDao> presences)
{
foreach (var presence in presences)
{
var existingPresence = _remoteDatabaseContext.PresenceDaos.FirstOrDefault(p =>
p.Date == presence.Date &&
p.UserId == presence.UserId &&
p.LessonNumber == presence.LessonNumber);
if (existingPresence == null)
{
_remoteDatabaseContext.PresenceDaos.Add(presence);
}
else
{
existingPresence.IsAttedance = presence.IsAttedance;
}
}
}
}
}