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-10-25 08:39:18 +00:00
|
|
|
{
|
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-10-25 08:39:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
2024-10-28 08:32:57 +00:00
|
|
|
&& x.ClassNumber <= lastClass && x.Date == date).ToList();
|
2024-10-25 08:39:18 +00:00
|
|
|
|
|
|
|
foreach (var pres in presToUpdate) {
|
2024-10-28 08:32:57 +00:00
|
|
|
pres.IsAttendence = false;
|
2024-10-25 08:39:18 +00:00
|
|
|
}
|
2024-11-06 04:10:09 +00:00
|
|
|
_remoteDatabaseContext.SaveChanges();
|
2024-10-25 08:39:18 +00:00
|
|
|
return true;
|
2024-10-24 11:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|