Demo/Data/Repository/PresenceRepositoryImpl.cs

52 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Domain.Models;
namespace Posechaemost.Data.Repository
{
public class PresenceRepositoryImpl: IPresenceRepository
{
public PresenceRepositoryImpl() {
GetAllPresences = LocalStaticData.presences;
}
public List<PresenceLocalEntity> GetAllPresences
{ get; set; }
public void AddPresence(PresenceLocalEntity presence)
{
PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault();
// GroupLocalEntity? group = new GroupLocalEntity();
presenceLocal.ClassNumber = presence.ClassNumber;
presence.UserGuid = presence.UserGuid;
presenceLocal.Date = presence.Date;
presenceLocal.IsAttendence = presence.IsAttendence;
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
{
return GetAllPresences;
}
public List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{
return GetAllPresences;
}
public bool UncheckAttendence(PresenceLocalEntity presence)
{
var presToUpdate = GetAllPresences
.Where(x => x.IsAttendence == presence.IsAttendence
&& x.UserGuid == presence.UserGuid && x.Date == presence.Date
&& x.ClassNumber == presence.ClassNumber).ToList();
foreach (var pres in presToUpdate) {
presence.IsAttendence = false;
}
return true;
}
}
}