slarny4/Demo1/Data/Repository/PresenceRepositoryImpl.cs
2024-10-28 15:42:04 +03:00

70 lines
2.2 KiB
C#

// C:\Users\adm\Source\Repos\presence1\Demo\Data\Repository\PresenceRepositoryImpl.cs
using System;
using System.Collections.Generic;
using System.Linq;
using AttendanceApp.Domain.Models;
using Demo.Data.LocalData;
using Demo.Data.LocalData.Entity;
using Demo.Data.RemoteData.RemoteDataBase;
namespace Demo.Data.Repository
{
public class PresenceRepositoryImpl : IPresenceRepository
{
private RemoteDatabaseContext context;
public PresenceRepositoryImpl(RemoteDatabaseContext context)
{
this.context = context;
}
public void AddPresence(LocalPresence presence)
{
LocalStaticData.Presences.Add(presence);
}
public IEnumerable<LocalPresence> GetAllPresences()
{
return LocalStaticData.Presences;
}
public IEnumerable<object> GetPresenceByGroup(int groupId)
{
throw new NotImplementedException();
}
public IEnumerable<object> GetPresenceByGroupAndDate(int groupId, DateTime date)
{
throw new NotImplementedException();
}
public IEnumerable<LocalPresence> GetPresencesByGroupAndDate(int groupId, DateTime date)
{
var usersInGroup = LocalStaticData.Users.Where(u => u.GroupID == groupId).Select(u => u.Id).ToList();
return LocalStaticData.Presences.Where(p => usersInGroup.Contains(p.UserId) && p.ClassDate.Date == date.Date);
}
public void UpdatePresence(LocalPresence presence)
{
var existingPresence = LocalStaticData.Presences.FirstOrDefault(p =>
p.UserId == presence.UserId &&
p.ClassDate.Date == presence.ClassDate.Date &&
p.LessonNumber == presence.LessonNumber);
if (existingPresence != null)
{
existingPresence.WasPresent = presence.WasPresent;
}
}
public void UpdatePresence(Presence presence)
{
throw new NotImplementedException();
}
IEnumerable<LocalPresence> IPresenceRepository.GetPresenceByGroup(int groupId)
{
throw new NotImplementedException();
}
}
}