erp-platform/api/src/Kurs.Platform.Domain/Classroom/Classroom.cs

90 lines
2.6 KiB
C#
Raw Normal View History

2025-08-25 18:01:57 +00:00
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities.Auditing;
namespace Kurs.Platform.Entities;
2025-08-26 05:59:39 +00:00
public class Classroom : FullAuditedEntity<Guid>
2025-08-25 18:01:57 +00:00
{
public string Name { get; set; }
public string Description { get; set; }
public string Subject { get; set; }
public Guid? TeacherId { get; set; }
public string TeacherName { get; set; }
public DateTime ScheduledStartTime { get; set; }
public DateTime? ActualStartTime { get; set; }
public DateTime? EndTime { get; set; }
public int Duration { get; set; } // minutes
public int MaxParticipants { get; set; }
public bool IsActive { get; set; }
public bool IsScheduled { get; set; }
public int ParticipantCount { get; set; }
2025-08-26 05:59:39 +00:00
public virtual ICollection<ClassParticipant> Participants { get; set; }
public virtual ICollection<ClassAttandance> AttendanceRecords { get; set; }
public virtual ICollection<ClassChat> ChatMessages { get; set; }
2025-08-25 18:01:57 +00:00
2025-08-26 05:59:39 +00:00
protected Classroom()
2025-08-25 18:01:57 +00:00
{
2025-08-26 05:59:39 +00:00
Participants = new HashSet<ClassParticipant>();
AttendanceRecords = new HashSet<ClassAttandance>();
ChatMessages = new HashSet<ClassChat>();
2025-08-25 18:01:57 +00:00
}
2025-08-26 05:59:39 +00:00
public Classroom(
2025-08-25 18:01:57 +00:00
Guid id,
string name,
string description,
string subject,
Guid? teacherId,
string teacherName,
DateTime scheduledStartTime,
int duration,
int maxParticipants
) : base(id)
{
Name = name;
Description = description;
Subject = subject;
TeacherId = teacherId;
TeacherName = teacherName;
ScheduledStartTime = scheduledStartTime;
Duration = duration;
MaxParticipants = maxParticipants;
IsActive = false;
IsScheduled = true;
ParticipantCount = 0;
2025-08-26 05:59:39 +00:00
Participants = new HashSet<ClassParticipant>();
AttendanceRecords = new HashSet<ClassAttandance>();
ChatMessages = new HashSet<ClassChat>();
2025-08-25 18:01:57 +00:00
}
public void StartClass()
{
if (IsActive)
throw new InvalidOperationException("Class is already active");
IsActive = true;
ActualStartTime = DateTime.UtcNow;
}
public void EndClass()
{
if (!IsActive)
throw new InvalidOperationException("Class is not active");
IsActive = false;
EndTime = DateTime.UtcNow;
}
public bool CanJoin()
{
var now = DateTime.UtcNow;
var tenMinutesBefore = ScheduledStartTime.AddMinutes(-10);
var twoHoursAfter = ScheduledStartTime.AddHours(2);
return now >= tenMinutesBefore && now <= twoHoursAfter && ParticipantCount < MaxParticipants;
}
}