58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
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<PresenceDao> GetPresenceByGroup(int groupId)
|
|
{
|
|
return _remoteDatabaseContext.PresencesDaos
|
|
.Where(p => p.GroupId == groupId)
|
|
.ToList();
|
|
}
|
|
|
|
public List<PresenceDao> 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;
|
|
}
|
|
}
|
|
}
|