presence/Demo/Data/Repository/SQLPresenceRepository.cs

67 lines
2.5 KiB
C#
Raw Normal View History

2024-10-25 08:47:11 +00:00
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
2024-11-01 09:42:31 +00:00
using Microsoft.EntityFrameworkCore;
2024-10-25 08:47:11 +00:00
using System;
using System.Collections.Generic;
2024-11-01 09:42:31 +00:00
using System.Data;
2024-10-25 08:47:11 +00:00
using System.Linq;
using System.Text;
2024-11-01 09:42:31 +00:00
using System.Text.RegularExpressions;
2024-10-25 08:47:11 +00:00
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public class SQLPresenceRepositoryImpl : IPresenceRepository
{
private readonly RemoteDatabaseContext _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
2024-11-01 09:42:31 +00:00
public List<PresenceDao> GetPresenceForAbsent(DateTime date, int GroupId)
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == GroupId && p.Date==DateOnly.FromDateTime(date)).ToList();
}
2024-10-28 12:03:51 +00:00
public List<PresenceDao> GetPresenceByDateAndGroup(DateTime date, int groupId)
2024-10-25 08:47:11 +00:00
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.Date == DateOnly.FromDateTime(date) &&
2024-10-25 09:41:35 +00:00
_remoteDatabaseContext.Users.Any(u => u.GroupId == groupId && u.UserId == p.UserId)).ToList();
2024-10-25 08:47:11 +00:00
}
// Реализация метода для получения всех данных по группе
2024-10-28 12:03:51 +00:00
public List<PresenceDao> GetPresenceByGroup(int groupId)
2024-10-25 08:47:11 +00:00
{
return _remoteDatabaseContext.PresenceDaos.Where(p => p.GroupId == groupId).ToList();
}
2024-10-28 12:03:51 +00:00
public void SavePresence(List<PresenceDao> presences)
2024-10-25 08:47:11 +00:00
{
2024-10-31 11:48:30 +00:00
_remoteDatabaseContext.PresenceDaos.AddRange(presences.Select(it => new PresenceDao
2024-10-25 08:47:11 +00:00
{
2024-10-31 11:48:30 +00:00
Date = it.Date,
IsAttedance = it.IsAttedance,
LessonNumber = it.LessonNumber,
2024-11-01 09:42:31 +00:00
UserId = it.UserId,
GroupId = it.GroupId
2024-10-31 11:48:30 +00:00
}));
_remoteDatabaseContext.SaveChanges();
2024-10-25 08:47:11 +00:00
}
2024-10-31 11:48:30 +00:00
2024-11-01 09:42:31 +00:00
public DateOnly? GetLastDateByGroupId(int groupId)
{
// Проверяем наличие записей о посещаемости в базе данных для данной группы.
var lastDate = _remoteDatabaseContext.PresenceDaos
.Where(p => p.GroupId == groupId)
.OrderByDescending(p => p.Date)
.Select(p => p.Date)
.FirstOrDefault();
return lastDate == default ? (DateOnly?)null : lastDate;
}
2024-10-25 08:47:11 +00:00
}
}