39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using LehrerApp.Core.Interfaces;
|
||
using LehrerApp.Core.Models;
|
||
|
||
namespace LehrerApp.Data.Repositories;
|
||
|
||
public class StudentRepository(LiteDbContext db) : IStudentRepository
|
||
{
|
||
public Student? GetById(Guid id) =>
|
||
db.Students.FindById(id);
|
||
|
||
public List<Student> GetAll(bool includeInactive = false) =>
|
||
includeInactive
|
||
? db.Students.FindAll().OrderBy(s => s.LastName).ToList()
|
||
: db.Students.Find(s => s.IsActive).OrderBy(s => s.LastName).ToList();
|
||
|
||
public List<Student> GetByGroup(Guid groupId, string schoolYear)
|
||
{
|
||
// Enrollment als Bindeglied – Schüler-IDs der Gruppe ermitteln
|
||
var studentIds = db.Enrollments
|
||
.Find(e => e.GroupId == groupId && e.SchoolYear == schoolYear)
|
||
.Select(e => e.StudentId)
|
||
.ToHashSet();
|
||
|
||
return db.Students
|
||
.Find(s => studentIds.Contains(s.Id))
|
||
.OrderBy(s => s.LastName)
|
||
.ToList();
|
||
}
|
||
|
||
public void Save(Student student)
|
||
{
|
||
student.UpdatedAt = DateTime.UtcNow;
|
||
db.Students.Upsert(student);
|
||
}
|
||
|
||
public void Delete(Guid id) =>
|
||
db.Students.Delete(id);
|
||
}
|