43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using data.DAO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace data.Repository
|
|
{
|
|
public class SQLPresenceRepository : IPresenceRepository
|
|
{
|
|
private readonly DatabaseContext _context;
|
|
|
|
public SQLPresenceRepository(DatabaseContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IEnumerable<Diary> GetPresence(
|
|
int groupId,
|
|
int? subjectId = null,
|
|
DateTime? date = null,
|
|
int? studentId = null)
|
|
{
|
|
var query = _context.Diaries
|
|
.Include(p => p.Student)
|
|
.Include(p => p.StudentGroupSubject)
|
|
.ThenInclude(p => p.Subject)
|
|
.Where(p => p.Student.GroupId == groupId);
|
|
|
|
if (subjectId.HasValue)
|
|
query = query.Where(p => p.StudentGroupSubject.Subject.Id == subjectId.Value);
|
|
|
|
if (date.HasValue)
|
|
query = query.Where(p => p.Date == DateOnly.FromDateTime(date.Value));
|
|
|
|
if (studentId.HasValue)
|
|
query = query.Where(p => p.Student.Id == studentId.Value);
|
|
|
|
return query.ToList();
|
|
}
|
|
}
|
|
}
|