Initial
This commit is contained in:
95
LehrerApp.Data/Repositories/GroupExamRepositories.cs
Normal file
95
LehrerApp.Data/Repositories/GroupExamRepositories.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
|
||||
namespace LehrerApp.Data.Repositories;
|
||||
|
||||
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 group)
|
||||
{
|
||||
group.UpdatedAt = DateTime.UtcNow;
|
||||
db.Groups.Upsert(group);
|
||||
}
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.Groups.Delete(id);
|
||||
}
|
||||
|
||||
public class EnrollmentRepository(LiteDbContext db) : IEnrollmentRepository
|
||||
{
|
||||
public List<Enrollment> GetByStudent(Guid studentId) =>
|
||||
db.Enrollments.Find(e => e.StudentId == studentId).ToList();
|
||||
|
||||
public List<Enrollment> GetByGroup(Guid groupId) =>
|
||||
db.Enrollments.Find(e => e.GroupId == groupId).ToList();
|
||||
|
||||
public List<Enrollment> GetByGroupAndYear(Guid groupId, string schoolYear) =>
|
||||
db.Enrollments
|
||||
.Find(e => e.GroupId == groupId && e.SchoolYear == schoolYear)
|
||||
.ToList();
|
||||
|
||||
public void Save(Enrollment enrollment) =>
|
||||
db.Enrollments.Upsert(enrollment);
|
||||
|
||||
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 exam)
|
||||
{
|
||||
exam.UpdatedAt = DateTime.UtcNow;
|
||||
db.Exams.Upsert(exam);
|
||||
}
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.Exams.Delete(id);
|
||||
}
|
||||
|
||||
public class ExamResultRepository(LiteDbContext db) : IExamResultRepository
|
||||
{
|
||||
public List<ExamResult> GetByExam(Guid examId) =>
|
||||
db.ExamResults.Find(r => r.ExamId == examId).ToList();
|
||||
|
||||
public List<ExamResult> GetByStudent(Guid studentId) =>
|
||||
db.ExamResults.Find(r => r.StudentId == studentId).ToList();
|
||||
|
||||
public ExamResult? GetByExamAndStudent(Guid examId, Guid studentId) =>
|
||||
db.ExamResults.FindOne(r => r.ExamId == examId && r.StudentId == studentId);
|
||||
|
||||
public void Save(ExamResult result)
|
||||
{
|
||||
result.UpdatedAt = DateTime.UtcNow;
|
||||
db.ExamResults.Upsert(result);
|
||||
}
|
||||
|
||||
public void SaveMany(List<ExamResult> results)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
foreach (var r in results) r.UpdatedAt = now;
|
||||
db.ExamResults.Upsert(results);
|
||||
}
|
||||
}
|
||||
140
LehrerApp.Data/Repositories/OtherRepositories.cs
Normal file
140
LehrerApp.Data/Repositories/OtherRepositories.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
|
||||
namespace LehrerApp.Data.Repositories;
|
||||
|
||||
public class GradeRepository(LiteDbContext db) : IGradeRepository
|
||||
{
|
||||
public List<Grade> GetByStudentAndGroup(Guid studentId, Guid groupId) =>
|
||||
db.Grades
|
||||
.Find(g => g.StudentId == studentId && g.GroupId == groupId)
|
||||
.OrderBy(g => g.Date)
|
||||
.ToList();
|
||||
|
||||
public List<Grade> GetByGroup(Guid groupId) =>
|
||||
db.Grades.Find(g => g.GroupId == groupId)
|
||||
.OrderBy(g => g.Date)
|
||||
.ToList();
|
||||
|
||||
public void Save(Grade grade) =>
|
||||
db.Grades.Upsert(grade);
|
||||
|
||||
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 groupId) =>
|
||||
db.Units.Find(u => u.GroupId == groupId)
|
||||
.OrderBy(u => u.StartDate)
|
||||
.ToList();
|
||||
|
||||
public void Save(Unit unit)
|
||||
{
|
||||
unit.UpdatedAt = DateTime.UtcNow;
|
||||
db.Units.Upsert(unit);
|
||||
}
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.Units.Delete(id);
|
||||
}
|
||||
|
||||
public class LessonRepository(LiteDbContext db) : ILessonRepository
|
||||
{
|
||||
public List<Lesson> GetByUnit(Guid unitId) =>
|
||||
db.Lessons.Find(l => l.UnitId == unitId)
|
||||
.OrderBy(l => l.Date)
|
||||
.ToList();
|
||||
|
||||
public List<Lesson> GetByGroupAndDate(Guid groupId, DateOnly date) =>
|
||||
db.Lessons.Find(l => l.GroupId == groupId && l.Date == date).ToList();
|
||||
|
||||
public List<Lesson> GetByGroupAndRange(Guid groupId, DateOnly from, DateOnly to) =>
|
||||
db.Lessons
|
||||
.Find(l => l.GroupId == groupId && l.Date >= from && l.Date <= to)
|
||||
.OrderBy(l => l.Date)
|
||||
.ToList();
|
||||
|
||||
public void Save(Lesson lesson)
|
||||
{
|
||||
lesson.UpdatedAt = DateTime.UtcNow;
|
||||
db.Lessons.Upsert(lesson);
|
||||
}
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.Lessons.Delete(id);
|
||||
}
|
||||
|
||||
public class DocumentationRepository(LiteDbContext db) : IDocumentationRepository
|
||||
{
|
||||
public List<Documentation> GetByStudent(Guid studentId) =>
|
||||
db.Documentation.Find(d => d.StudentId == studentId)
|
||||
.OrderByDescending(d => d.Date)
|
||||
.ToList();
|
||||
|
||||
public List<Documentation> GetByStudentAndType(Guid studentId, DocumentationType type) =>
|
||||
db.Documentation
|
||||
.Find(d => d.StudentId == studentId && d.Type == type)
|
||||
.OrderByDescending(d => d.Date)
|
||||
.ToList();
|
||||
|
||||
public void Save(Documentation doc)
|
||||
{
|
||||
doc.UpdatedAt = DateTime.UtcNow;
|
||||
db.Documentation.Upsert(doc);
|
||||
}
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.Documentation.Delete(id);
|
||||
}
|
||||
|
||||
public class WorkTaskRepository(LiteDbContext db) : IWorkTaskRepository
|
||||
{
|
||||
public List<WorkTask> GetByStatus(WorkTaskStatus status) =>
|
||||
db.Tasks.Find(t => t.Status == status)
|
||||
.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 task)
|
||||
{
|
||||
task.UpdatedAt = DateTime.UtcNow;
|
||||
db.Tasks.Upsert(task);
|
||||
}
|
||||
|
||||
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)
|
||||
.ThenBy(e => e.StartTime)
|
||||
.ToList();
|
||||
|
||||
public List<TimeEntry> GetByTask(Guid taskId) =>
|
||||
db.TimeEntries.Find(e => e.TaskId == taskId).ToList();
|
||||
|
||||
public void Save(TimeEntry entry) =>
|
||||
db.TimeEntries.Upsert(entry);
|
||||
|
||||
public void Delete(Guid id) =>
|
||||
db.TimeEntries.Delete(id);
|
||||
}
|
||||
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