Files
LehrerApp/LehrerApp.Data/Repositories/StudentRepository.cs
2026-03-29 23:47:31 +02:00

39 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}