| | | 1 | | namespace Syki.Back.Commands.Domain.Classes; |
| | | 2 | | |
| | | 3 | | public class Schedule |
| | | 4 | | { |
| | 0 | 5 | | public int Id { get; set; } |
| | 0 | 6 | | public int? ClassId { get; set; } |
| | 0 | 7 | | public int? ClassroomId { get; set; } |
| | 0 | 8 | | public int? TeacherId { get; set; } |
| | 0 | 9 | | public Day Day { get; set; } |
| | 0 | 10 | | public Hour Start { get; set; } |
| | 0 | 11 | | public Hour End { get; set; } |
| | | 12 | | |
| | 0 | 13 | | private Schedule() {} |
| | | 14 | | |
| | 0 | 15 | | public Schedule( |
| | 0 | 16 | | Day day, |
| | 0 | 17 | | Hour startAt, |
| | 0 | 18 | | Hour endAt |
| | 0 | 19 | | ) { |
| | 0 | 20 | | Day = day; |
| | 0 | 21 | | Start = startAt; |
| | 0 | 22 | | End = endAt; |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public static OneOf<Schedule, SykiError> New( |
| | | 26 | | Day day, |
| | | 27 | | Hour startAt, |
| | | 28 | | Hour endAt |
| | | 29 | | ) { |
| | 0 | 30 | | if (!day.IsValid()) return new InvalidDay(); |
| | 0 | 31 | | if (!startAt.IsValid()) return new InvalidHour(); |
| | 0 | 32 | | if (!endAt.IsValid()) return new InvalidHour(); |
| | | 33 | | |
| | 0 | 34 | | if (startAt == endAt || endAt < startAt) |
| | 0 | 35 | | return new InvalidSchedule(); |
| | | 36 | | |
| | 0 | 37 | | return new Schedule(day, startAt, endAt); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public int GetDiff() |
| | | 41 | | { |
| | 0 | 42 | | return Start.DiffInMinutes(End); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public bool Conflict(Schedule other) |
| | | 46 | | { |
| | 0 | 47 | | if (Day != other.Day) |
| | 0 | 48 | | return false; |
| | | 49 | | |
| | 0 | 50 | | if (Start == other.Start || End == other.End) |
| | 0 | 51 | | return true; |
| | | 52 | | |
| | 0 | 53 | | if (Start < other.Start && other.Start < End) |
| | 0 | 54 | | return true; |
| | | 55 | | |
| | 0 | 56 | | if (Start < other.End && other.End < End) |
| | 0 | 57 | | return true; |
| | | 58 | | |
| | 0 | 59 | | if (other.Start < Start && Start < other.End) |
| | 0 | 60 | | return true; |
| | | 61 | | |
| | 0 | 62 | | if (other.Start < End && End < other.End) |
| | 0 | 63 | | return true; |
| | | 64 | | |
| | 0 | 65 | | return false; |
| | | 66 | | } |
| | | 67 | | } |