Demo/Data/Repository/PresenceRepositoryImpl.cs

64 lines
2.2 KiB
C#
Raw Permalink Normal View History

2024-10-24 11:13:46 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2024-11-06 04:10:09 +00:00
using Microsoft.EntityFrameworkCore;
2024-10-24 11:13:46 +00:00
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
2024-11-06 04:10:09 +00:00
using Posechaemost.Data.RemoteData.RemoteDataBase;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
2024-10-24 11:13:46 +00:00
using Posechaemost.Domain.Models;
namespace Posechaemost.Data.Repository
{
2024-11-06 04:10:09 +00:00
public class SQLPresenceRepositoryImpl: IPresenceRepository
2024-10-24 11:13:46 +00:00
{
2024-11-06 04:10:09 +00:00
private readonly RemoteDataBaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDataBaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
2024-10-24 11:13:46 +00:00
}
2024-11-06 04:10:09 +00:00
public bool AddPresence(PresenceDao presence)
{
2024-11-06 04:10:09 +00:00
var presenceDao = new PresenceDao
{
Date = presence.Date,
ClassNumber = presence.ClassNumber,
UserId = presence.UserId,
User = presence.User
};
_remoteDatabaseContext.Presences.Add(presenceDao);
_remoteDatabaseContext.SaveChanges();
return true;
}
2024-11-06 04:10:09 +00:00
public List<PresenceDao> GetPresenceByGroup(int groupId)
2024-10-24 11:13:46 +00:00
{
2024-11-06 04:10:09 +00:00
var listPresences = _remoteDatabaseContext.Presences
.Where(x => x.GroupId == groupId).ToList();
return listPresences;
2024-10-24 11:13:46 +00:00
}
2024-11-06 04:10:09 +00:00
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date)
2024-10-24 11:13:46 +00:00
{
2024-11-06 04:10:09 +00:00
var listPresences = _remoteDatabaseContext.Presences
.Where(x => x.GroupId == groupId && x.Date == date).ToList();
return listPresences;
2024-10-24 11:13:46 +00:00
}
2024-11-06 04:10:09 +00:00
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId)
2024-10-24 11:13:46 +00:00
{
2024-11-06 04:10:09 +00:00
var presToUpdate = _remoteDatabaseContext.Presences
.Where(x => x.UserId == userId && x.ClassNumber >= firstClass
&& x.ClassNumber <= lastClass && x.Date == date).ToList();
foreach (var pres in presToUpdate) {
pres.IsAttendence = false;
}
2024-11-06 04:10:09 +00:00
_remoteDatabaseContext.SaveChanges();
return true;
2024-10-24 11:13:46 +00:00
}
}
}