Details Lerngruppe, Archiv, Stub Import
This commit is contained in:
@@ -16,6 +16,7 @@ public class LiteDbContext : IDisposable
|
||||
{
|
||||
Connection = ConnectionType.Shared,
|
||||
});
|
||||
MigrateExistingData();
|
||||
EnsureIndexes();
|
||||
}
|
||||
|
||||
@@ -38,11 +39,25 @@ public class LiteDbContext : IDisposable
|
||||
|
||||
public void Checkpoint() => _db.Checkpoint();
|
||||
|
||||
private void MigrateExistingData()
|
||||
{
|
||||
var groups = _db.GetCollection<BsonDocument>("groups");
|
||||
var missingArchiveState = groups.FindAll()
|
||||
.Where(g => !g.ContainsKey(nameof(LearningGroup.IsActive)))
|
||||
.ToList();
|
||||
foreach (var group in missingArchiveState)
|
||||
{
|
||||
group[nameof(LearningGroup.IsActive)] = true;
|
||||
groups.Update(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureIndexes()
|
||||
{
|
||||
Students.EnsureIndex(x => x.LastName);
|
||||
Students.EnsureIndex(x => x.IsActive);
|
||||
Groups.EnsureIndex(x => x.SchoolYear);
|
||||
Groups.EnsureIndex(x => x.IsActive);
|
||||
Enrollments.EnsureIndex(x => x.StudentId);
|
||||
Enrollments.EnsureIndex(x => x.GroupId);
|
||||
Enrollments.EnsureIndex(x => x.SchoolYear);
|
||||
|
||||
@@ -23,12 +23,52 @@ public class StudentRepository(LiteDbContext db) : IStudentRepository
|
||||
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 List<LearningGroup> GetAll(bool includeInactive = false) =>
|
||||
(includeInactive ? db.Groups.FindAll() : db.Groups.Find(g => g.IsActive))
|
||||
.OrderBy(g => g.SchoolYear).ThenBy(g => g.Name).ToList();
|
||||
public List<LearningGroup> GetBySchoolYear(string schoolYear, bool includeInactive = false) =>
|
||||
(includeInactive
|
||||
? db.Groups.Find(g => g.SchoolYear == schoolYear)
|
||||
: db.Groups.Find(g => g.SchoolYear == schoolYear && g.IsActive))
|
||||
.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 void Delete(Guid id)
|
||||
{
|
||||
foreach (var enrollment in db.Enrollments.Find(e => e.GroupId == id).ToList())
|
||||
db.Enrollments.Delete(enrollment.Id);
|
||||
|
||||
foreach (var exam in db.Exams.Find(e => e.GroupId == id).ToList())
|
||||
{
|
||||
foreach (var result in db.ExamResults.Find(r => r.ExamId == exam.Id).ToList())
|
||||
db.ExamResults.Delete(result.Id);
|
||||
db.Exams.Delete(exam.Id);
|
||||
}
|
||||
|
||||
foreach (var grade in db.Grades.Find(g => g.GroupId == id).ToList())
|
||||
db.Grades.Delete(grade.Id);
|
||||
|
||||
foreach (var unit in db.Units.Find(u => u.GroupId == id).ToList())
|
||||
{
|
||||
foreach (var lesson in db.Lessons.Find(l => l.UnitId == unit.Id).ToList())
|
||||
db.Lessons.Delete(lesson.Id);
|
||||
db.Units.Delete(unit.Id);
|
||||
}
|
||||
|
||||
foreach (var lesson in db.Lessons.Find(l => l.GroupId == id).ToList())
|
||||
db.Lessons.Delete(lesson.Id);
|
||||
|
||||
foreach (var session in db.ParticipationSessions.Find(s => s.GroupId == id).ToList())
|
||||
{
|
||||
foreach (var entry in db.ParticipationEntries.Find(e => e.SessionId == session.Id).ToList())
|
||||
db.ParticipationEntries.Delete(entry.Id);
|
||||
db.ParticipationSessions.Delete(session.Id);
|
||||
}
|
||||
|
||||
foreach (var aspect in db.ParticipationAspects.Find(a => a.GroupId == id).ToList())
|
||||
db.ParticipationAspects.Delete(aspect.Id);
|
||||
|
||||
db.Groups.Delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
public class EnrollmentRepository(LiteDbContext db) : IEnrollmentRepository
|
||||
|
||||
Reference in New Issue
Block a user