Raspisanie/Zurnal/Date/Repository/SQLRepos/SQLNado.cs
2024-11-11 14:41:12 +03:00

74 lines
2.2 KiB
C#

using Zurnal.Date.LocalDate;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Data.Repository
{
public class SQLGroupRepositoryImpl:IGroupRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
public SQLGroupRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) {
_remoteDataBaseContext = remoteDataBaseContext;
}
public List<GroupDao> AllGroup => throw new NotImplementedException();
public bool AddGroup(GroupLocalEntity newGroup)
{
GroupDao groupDao = new GroupDao { GroupName = newGroup.Name };
var result = _remoteDataBaseContext.Group.Add(groupDao);
if (result != null) {
_remoteDataBaseContext.SaveChanges();
return true; }
return false;
}
public List<GroupLocalEntity> GetAllGroup()
{
return _remoteDataBaseContext.Group.Select(group => new GroupLocalEntity{
Id = group.Id,
Name = group.GroupName}
).ToList();
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
}
public class SQLPresenceRepositoryImpl: IPresenceRepository
{
private readonly RemoteDateBaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDateBaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public DateOnly? GetLastDateByGroupId(int groupId)
{
var lastDate = _remoteDatabaseContext.Presence
.Where(p => p.GroupId == groupId)
.OrderByDescending(p => p.Date)
.Select(p => p.Date)
.FirstOrDefault();
return lastDate == default ? (DateOnly?)null : lastDate;
}
}
}