Initial
This commit is contained in:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user