| | 1 | | namespace Syki.Back.Features.Academic.CreateClass; |
| | 2 | |
|
| | 3 | | public class Schedule |
| | 4 | | { |
| 716 | 5 | | public Guid Id { get; set; } |
| 2 | 6 | | public Guid? ClassId { get; set; } |
| 2 | 7 | | public Guid? ClassroomId { get; set; } |
| 2 | 8 | | public Guid? TeacherId { get; set; } |
| 91520 | 9 | | public Day Day { get; set; } |
| 27274 | 10 | | public Hour Start { get; set; } |
| 27174 | 11 | | public Hour End { get; set; } |
| | 12 | |
|
| 1272 | 13 | | private Schedule() {} |
| | 14 | |
|
| 714 | 15 | | public Schedule( |
| 714 | 16 | | Day day, |
| 714 | 17 | | Hour startAt, |
| 714 | 18 | | Hour endAt |
| 714 | 19 | | ) { |
| 714 | 20 | | Id = Guid.CreateVersion7(); |
| 714 | 21 | | Day = day; |
| 714 | 22 | | Start = startAt; |
| 714 | 23 | | End = endAt; |
| 714 | 24 | | } |
| | 25 | |
|
| | 26 | | public static OneOf<Schedule, SykiError> New( |
| | 27 | | Day day, |
| | 28 | | Hour startAt, |
| | 29 | | Hour endAt |
| | 30 | | ) { |
| 676 | 31 | | if (!day.IsValid()) return new InvalidDay(); |
| 674 | 32 | | if (!startAt.IsValid()) return new InvalidHour(); |
| 672 | 33 | | if (!endAt.IsValid()) return new InvalidHour(); |
| | 34 | |
|
| 668 | 35 | | if (startAt == endAt || endAt < startAt) |
| 16 | 36 | | return new InvalidSchedule(); |
| | 37 | |
|
| 652 | 38 | | return new Schedule(day, startAt, endAt); |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public int GetDiff() |
| | 42 | | { |
| 12808 | 43 | | return Start.DiffInMinutes(End); |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public bool Conflict(Schedule other) |
| | 47 | | { |
| 46 | 48 | | if (Day != other.Day) |
| 8 | 49 | | return false; |
| | 50 | |
|
| 38 | 51 | | if (Start == other.Start || End == other.End) |
| 4 | 52 | | return true; |
| | 53 | |
|
| 34 | 54 | | if (Start < other.Start && other.Start < End) |
| 16 | 55 | | return true; |
| | 56 | |
|
| 18 | 57 | | if (Start < other.End && other.End < End) |
| 2 | 58 | | return true; |
| | 59 | |
|
| 16 | 60 | | if (other.Start < Start && Start < other.End) |
| 4 | 61 | | return true; |
| | 62 | |
|
| 12 | 63 | | if (other.Start < End && End < other.End) |
| 0 | 64 | | return true; |
| | 65 | |
|
| 12 | 66 | | return false; |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public override string ToString() |
| | 70 | | { |
| 18 | 71 | | return $"{Day.GetDescription()} {Start.GetDescription()}-{End.GetDescription()}"; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | public ScheduleOut ToOut() |
| | 75 | | { |
| 638 | 76 | | return new() |
| 638 | 77 | | { |
| 638 | 78 | | Day = Day, |
| 638 | 79 | | StartAt = Start, |
| 638 | 80 | | EndAt = End, |
| 638 | 81 | | }; |
| | 82 | | } |
| | 83 | | } |