211 lines
10 KiB
C#
211 lines
10 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() : db.Students.Find(s => s.IsActive))
|
|
.OrderBy(s => s.LastName).ToList();
|
|
public List<Student> GetByGroup(Guid groupId, string schoolYear)
|
|
{
|
|
var ids = db.Enrollments
|
|
.Find(e => e.GroupId == groupId && e.SchoolYear == schoolYear)
|
|
.Select(e => e.StudentId).ToHashSet();
|
|
return db.Students.Find(s => ids.Contains(s.Id)).OrderBy(s => s.LastName).ToList();
|
|
}
|
|
public void Save(Student s) { s.UpdatedAt = DateTime.UtcNow; db.Students.Upsert(s); }
|
|
public void Delete(Guid id) => db.Students.Delete(id);
|
|
}
|
|
|
|
public class GroupRepository(LiteDbContext db) : IGroupRepository
|
|
{
|
|
public LearningGroup? GetById(Guid id) => db.Groups.FindById(id);
|
|
public List<LearningGroup> GetAll() =>
|
|
db.Groups.FindAll().OrderBy(g => g.SchoolYear).ThenBy(g => g.Name).ToList();
|
|
public List<LearningGroup> GetBySchoolYear(string schoolYear) =>
|
|
db.Groups.Find(g => g.SchoolYear == schoolYear).OrderBy(g => g.Name).ToList();
|
|
public void Save(LearningGroup g) { g.UpdatedAt = DateTime.UtcNow; db.Groups.Upsert(g); }
|
|
public void Delete(Guid id) => db.Groups.Delete(id);
|
|
}
|
|
|
|
public class EnrollmentRepository(LiteDbContext db) : IEnrollmentRepository
|
|
{
|
|
public List<Enrollment> GetByStudent(Guid id) =>
|
|
db.Enrollments.Find(e => e.StudentId == id).ToList();
|
|
public List<Enrollment> GetByGroup(Guid id) =>
|
|
db.Enrollments.Find(e => e.GroupId == id).ToList();
|
|
public List<Enrollment> GetByGroupAndYear(Guid groupId, string sy) =>
|
|
db.Enrollments.Find(e => e.GroupId == groupId && e.SchoolYear == sy).ToList();
|
|
public void Save(Enrollment e) => db.Enrollments.Upsert(e);
|
|
public void Delete(Guid id) => db.Enrollments.Delete(id);
|
|
}
|
|
|
|
public class ExamRepository(LiteDbContext db) : IExamRepository
|
|
{
|
|
public Exam? GetById(Guid id) => db.Exams.FindById(id);
|
|
public List<Exam> GetByGroup(Guid groupId) =>
|
|
db.Exams.Find(e => e.GroupId == groupId).OrderByDescending(e => e.Date).ToList();
|
|
public void Save(Exam e) { e.UpdatedAt = DateTime.UtcNow; db.Exams.Upsert(e); }
|
|
public void Delete(Guid id) => db.Exams.Delete(id);
|
|
}
|
|
|
|
public class ExamResultRepository(LiteDbContext db) : IExamResultRepository
|
|
{
|
|
public List<ExamResult> GetByExam(Guid id) =>
|
|
db.ExamResults.Find(r => r.ExamId == id).ToList();
|
|
public List<ExamResult> GetByStudent(Guid id) =>
|
|
db.ExamResults.Find(r => r.StudentId == id).ToList();
|
|
public ExamResult? GetByExamAndStudent(Guid examId, Guid studentId) =>
|
|
db.ExamResults.FindOne(r => r.ExamId == examId && r.StudentId == studentId);
|
|
public void Save(ExamResult r) { r.UpdatedAt = DateTime.UtcNow; db.ExamResults.Upsert(r); }
|
|
public void SaveMany(List<ExamResult> results)
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
foreach (var r in results) r.UpdatedAt = now;
|
|
db.ExamResults.Upsert(results);
|
|
}
|
|
}
|
|
|
|
public class GradeRepository(LiteDbContext db) : IGradeRepository
|
|
{
|
|
public List<Grade> GetByStudentAndGroup(Guid sid, Guid gid) =>
|
|
db.Grades.Find(g => g.StudentId == sid && g.GroupId == gid).OrderBy(g => g.Date).ToList();
|
|
public List<Grade> GetByGroup(Guid id) =>
|
|
db.Grades.Find(g => g.GroupId == id).OrderBy(g => g.Date).ToList();
|
|
public void Save(Grade g) => db.Grades.Upsert(g);
|
|
public void Delete(Guid id) => db.Grades.Delete(id);
|
|
}
|
|
|
|
public class UnitRepository(LiteDbContext db) : IUnitRepository
|
|
{
|
|
public Unit? GetById(Guid id) => db.Units.FindById(id);
|
|
public List<Unit> GetByGroup(Guid id) =>
|
|
db.Units.Find(u => u.GroupId == id).OrderBy(u => u.StartDate).ToList();
|
|
public void Save(Unit u) { u.UpdatedAt = DateTime.UtcNow; db.Units.Upsert(u); }
|
|
public void Delete(Guid id) => db.Units.Delete(id);
|
|
}
|
|
|
|
public class LessonRepository(LiteDbContext db) : ILessonRepository
|
|
{
|
|
public List<Lesson> GetByUnit(Guid id) =>
|
|
db.Lessons.Find(l => l.UnitId == id).OrderBy(l => l.Date).ToList();
|
|
public List<Lesson> GetByGroupAndDate(Guid gid, DateOnly date) =>
|
|
db.Lessons.Find(l => l.GroupId == gid && l.Date == date).ToList();
|
|
public List<Lesson> GetByGroupAndRange(Guid gid, DateOnly from, DateOnly to) =>
|
|
db.Lessons.Find(l => l.GroupId == gid && l.Date >= from && l.Date <= to)
|
|
.OrderBy(l => l.Date).ToList();
|
|
public void Save(Lesson l) { l.UpdatedAt = DateTime.UtcNow; db.Lessons.Upsert(l); }
|
|
public void Delete(Guid id) => db.Lessons.Delete(id);
|
|
}
|
|
|
|
public class DocumentationRepository(LiteDbContext db) : IDocumentationRepository
|
|
{
|
|
public List<Documentation> GetByStudent(Guid id) =>
|
|
db.Documentation.Find(d => d.StudentId == id).OrderByDescending(d => d.Date).ToList();
|
|
public List<Documentation> GetByStudentAndType(Guid sid, DocumentationType type) =>
|
|
db.Documentation.Find(d => d.StudentId == sid && d.Type == type)
|
|
.OrderByDescending(d => d.Date).ToList();
|
|
public void Save(Documentation d) { d.UpdatedAt = DateTime.UtcNow; db.Documentation.Upsert(d); }
|
|
public void Delete(Guid id) => db.Documentation.Delete(id);
|
|
}
|
|
|
|
public class WorkTaskRepository(LiteDbContext db) : IWorkTaskRepository
|
|
{
|
|
public List<WorkTask> GetByStatus(WorkTaskStatus s) =>
|
|
db.Tasks.Find(t => t.Status == s).OrderBy(t => t.DueDate).ToList();
|
|
public List<WorkTask> GetAll() =>
|
|
db.Tasks.FindAll().OrderBy(t => t.Status).ThenBy(t => t.DueDate).ToList();
|
|
public void Save(WorkTask t) { t.UpdatedAt = DateTime.UtcNow; db.Tasks.Upsert(t); }
|
|
public void Delete(Guid id) => db.Tasks.Delete(id);
|
|
}
|
|
|
|
public class TimeEntryRepository(LiteDbContext db) : ITimeEntryRepository
|
|
{
|
|
public List<TimeEntry> GetByDate(DateOnly date) =>
|
|
db.TimeEntries.Find(e => e.Date == date).OrderBy(e => e.StartTime).ToList();
|
|
public List<TimeEntry> GetByDateRange(DateOnly from, DateOnly to) =>
|
|
db.TimeEntries.Find(e => e.Date >= from && e.Date <= to).OrderBy(e => e.Date).ToList();
|
|
public List<TimeEntry> GetByTask(Guid id) =>
|
|
db.TimeEntries.Find(e => e.TaskId == id).ToList();
|
|
public void Save(TimeEntry e) => db.TimeEntries.Upsert(e);
|
|
public void Delete(Guid id) => db.TimeEntries.Delete(id);
|
|
}
|
|
|
|
public class ParticipationSessionRepository(LiteDbContext db) : IParticipationSessionRepository
|
|
{
|
|
public List<ParticipationSession> GetByGroup(Guid groupId) =>
|
|
db.ParticipationSessions.Find(s => s.GroupId == groupId).OrderByDescending(s => s.Date).ToList();
|
|
public ParticipationSession? GetById(Guid id) => db.ParticipationSessions.FindById(id);
|
|
public void Save(ParticipationSession s) { s.UpdatedAt = DateTime.UtcNow; db.ParticipationSessions.Upsert(s); }
|
|
public void Delete(Guid id)
|
|
{
|
|
db.ParticipationSessions.Delete(id);
|
|
foreach (var e in db.ParticipationEntries.Find(e => e.SessionId == id).ToList())
|
|
db.ParticipationEntries.Delete(e.Id);
|
|
}
|
|
}
|
|
|
|
public class ParticipationRepository(LiteDbContext db) : IParticipationRepository
|
|
{
|
|
public List<ParticipationEntry> GetBySession(Guid sessionId) =>
|
|
db.ParticipationEntries.Find(e => e.SessionId == sessionId).ToList();
|
|
public List<ParticipationEntry> GetByStudent(Guid studentId) =>
|
|
db.ParticipationEntries.Find(e => e.StudentId == studentId).ToList();
|
|
public ParticipationEntry? GetBySessionAndStudent(Guid sessionId, Guid studentId) =>
|
|
db.ParticipationEntries.FindOne(e => e.SessionId == sessionId && e.StudentId == studentId);
|
|
public void Save(ParticipationEntry e) { e.UpdatedAt = DateTime.UtcNow; db.ParticipationEntries.Upsert(e); }
|
|
public void SaveMany(List<ParticipationEntry> entries)
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
foreach (var e in entries) e.UpdatedAt = now;
|
|
db.ParticipationEntries.Upsert(entries);
|
|
}
|
|
public void DeleteBySession(Guid sessionId)
|
|
{
|
|
foreach (var e in db.ParticipationEntries.Find(e => e.SessionId == sessionId).ToList())
|
|
db.ParticipationEntries.Delete(e.Id);
|
|
}
|
|
}
|
|
|
|
public class ParticipationAspectRepository(LiteDbContext db) : IParticipationAspectRepository
|
|
{
|
|
public List<ParticipationAspect> GetDefaults() =>
|
|
db.ParticipationAspects.Find(a => a.GroupId == null && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
|
public List<ParticipationAspect> GetByGroup(Guid groupId) =>
|
|
db.ParticipationAspects.Find(a => a.GroupId == groupId && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
|
public void Save(ParticipationAspect a) { a.UpdatedAt = DateTime.UtcNow; db.ParticipationAspects.Upsert(a); }
|
|
public void Delete(Guid id) => db.ParticipationAspects.Delete(id);
|
|
}
|
|
|
|
public class SubjectRepository(LiteDbContext db) : ISubjectRepository
|
|
{
|
|
public List<Subject> GetAll() => db.Subjects.FindAll().OrderBy(s => s.Name).ToList();
|
|
public Subject? GetById(Guid id) => db.Subjects.FindById(id);
|
|
public Subject? GetByName(string name) =>
|
|
db.Subjects.FindOne(s => s.Name == name);
|
|
public void Save(Subject s) { s.UpdatedAt = DateTime.UtcNow; db.Subjects.Upsert(s); }
|
|
public void Delete(Guid id) => db.Subjects.Delete(id);
|
|
}
|
|
|
|
public class CompetencyDomainRepository(LiteDbContext db) : ICompetencyDomainRepository
|
|
{
|
|
public List<CompetencyDomain> GetBySubjectAndGrade(Guid subjectId, int gradeLevel) =>
|
|
db.CompetencyDomains
|
|
.Find(d => d.SubjectId == subjectId && d.GradeLevel == gradeLevel)
|
|
.OrderBy(d => d.SortOrder)
|
|
.ToList();
|
|
public CompetencyDomain? GetById(Guid id) => db.CompetencyDomains.FindById(id);
|
|
public void Save(CompetencyDomain d) { d.UpdatedAt = DateTime.UtcNow; db.CompetencyDomains.Upsert(d); }
|
|
public void Delete(Guid id) => db.CompetencyDomains.Delete(id);
|
|
public void DeleteBySubjectAndGrade(Guid subjectId, int gradeLevel)
|
|
{
|
|
foreach (var d in db.CompetencyDomains
|
|
.Find(d => d.SubjectId == subjectId && d.GradeLevel == gradeLevel)
|
|
.ToList())
|
|
db.CompetencyDomains.Delete(d.Id);
|
|
}
|
|
}
|