52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
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<PresenceDao> GetPresenceByDateAndGroup(DateTime date, int groupId)
|
|
{
|
|
return _remoteDatabaseContext.PresenceDaos.Where(p => p.Date == DateOnly.FromDateTime(date) &&
|
|
_remoteDatabaseContext.Users.Any(u => u.GroupId == groupId && u.UserId == p.UserId)).ToList();
|
|
}
|
|
|
|
// Реализация метода для получения всех данных по группе
|
|
public List<PresenceDao> GetPresenceByGroup(int groupId)
|
|
{
|
|
foreach (var user in _remoteDatabaseContext.PresenceDaos)
|
|
{
|
|
Console.WriteLine(user);
|
|
}
|
|
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == groupId).ToList();
|
|
}
|
|
|
|
public void SavePresence(List<PresenceDao> presences)
|
|
{
|
|
_remoteDatabaseContext.PresenceDaos.AddRange(presences.Select(it => new PresenceDao
|
|
{
|
|
Date = it.Date,
|
|
IsAttedance = it.IsAttedance,
|
|
LessonNumber = it.LessonNumber,
|
|
UserId = it.UserId
|
|
}));
|
|
_remoteDatabaseContext.SaveChanges();
|
|
}
|
|
|
|
}
|
|
}
|