Demo/Data/Repository/PresenceRepositoryImpl.cs

51 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(int firstClass, int lastClass, DateOnly date, Guid userGuid)
{
var presToUpdate = GetAllPresences
.Where(x => x.UserGuid == userGuid && x.ClassNumber >= firstClass
&& x.ClassNumber <= lastClass && x.Date == date).ToList();
foreach (var pres in presToUpdate) {
pres.IsAttendence = false;
}
return true;
}
}
}