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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-28 12:03:51 +00:00
|
|
|
|
public List<PresenceDao> GetPresenceByDateAndGroup(DateTime date, int groupId)
|
2024-10-25 08:47:11 +00:00
|
|
|
|
{
|
|
|
|
|
return _remoteDatabaseContext.PresenceDaos.Where(p => p.Date == DateOnly.FromDateTime(date) &&
|
2024-10-25 09:41:35 +00:00
|
|
|
|
_remoteDatabaseContext.Users.Any(u => u.GroupId == groupId && u.UserId == p.UserId)).ToList();
|
2024-10-25 08:47:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Реализация метода для получения всех данных по группе
|
2024-10-28 12:03:51 +00:00
|
|
|
|
public List<PresenceDao> GetPresenceByGroup(int groupId)
|
2024-10-25 08:47:11 +00:00
|
|
|
|
{
|
2024-10-28 12:03:51 +00:00
|
|
|
|
foreach (var user in _remoteDatabaseContext.PresenceDaos)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(user);
|
|
|
|
|
}
|
2024-10-25 08:47:11 +00:00
|
|
|
|
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == groupId).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-28 12:03:51 +00:00
|
|
|
|
public void SavePresence(List<PresenceDao> presences)
|
2024-10-25 08:47:11 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var presence in presences)
|
|
|
|
|
{
|
|
|
|
|
var existingPresence = _remoteDatabaseContext.PresenceDaos.FirstOrDefault(p =>
|
2024-10-28 12:03:51 +00:00
|
|
|
|
p.UserId == presence.UserId &&
|
2024-10-25 08:47:11 +00:00
|
|
|
|
p.Date == presence.Date &&
|
|
|
|
|
p.LessonNumber == presence.LessonNumber);
|
|
|
|
|
|
|
|
|
|
if (existingPresence == null)
|
|
|
|
|
{
|
|
|
|
|
_remoteDatabaseContext.PresenceDaos.Add(presence);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
existingPresence.IsAttedance = presence.IsAttedance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|