using presence.Data.LocalData; using presence.Data.LocalData.Entity; using presence.Data.RemoteData.RemoteDatabase; using presence.Data.RemoteData.RemoteDatabase.DAO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace presence.Data.Repository { public class SQLPresenceRepositoryImpl : IPresenceRepository { private readonly RemoteDatabaseContext _remoteDatabaseContext; public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) { _remoteDatabaseContext = remoteDatabaseContext; } public void AddPresence(PresenceDao presence) { _remoteDatabaseContext.PresencesDaos.Add(presence); _remoteDatabaseContext.SaveChanges(); } public List GetPresenceByGroup(int groupId) { return _remoteDatabaseContext.PresencesDaos .Where(p => p.GroupId == groupId) .ToList(); } public List GetPresenceByGroupAndDate(int groupId, DateOnly date) { return _remoteDatabaseContext.PresencesDaos .Where(p => p.GroupId == groupId && p.Date == date) .ToList(); } public bool UnCheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) { var presToUpdate = _remoteDatabaseContext.PresencesDaos .Where(x => x.UserDaoUserId == userId && x.LessonNumber >= firstClass && x.LessonNumber <= lastClass && x.Date == date).ToList(); foreach (var presence in presToUpdate) { presence.IsAttedance = false; } _remoteDatabaseContext.SaveChanges(); return true; } } }