Initial
This commit is contained in:
38
LehrerApp.Data/Repositories/StudentRepository.cs
Normal file
38
LehrerApp.Data/Repositories/StudentRepository.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user