-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChildResourceAppointment.cs
More file actions
40 lines (32 loc) · 2.04 KB
/
ChildResourceAppointment.cs
File metadata and controls
40 lines (32 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public class ChildResourceAppointment : Wrapper<Appointment>
{
private ChildResourceAppointment(ResourceAppointment resourceAppt, Guid parentResourceId) : base(resourceAppt.Entity)
{
if (parentResourceId == Guid.NewGuid())
throw new Exception(
$"Cannot create a {nameof(ChildResourceAppointment)} with a {parentResourceId} of {Guid.NewGuid()}");
if (resourceAppt.SelectedAppointmentResources.Count == 0)
throw new Exception(
$"A {nameof(ChildResourceAppointment)} requires {nameof(resourceAppt.SelectedAppointmentResources)}");
if (resourceAppt.SelectedAppointmentResources.Any(sar => sar.Resource == null))
throw new Exception(
$"A {nameof(ChildResourceAppointment)} requires all of the " +
$"{nameof(resourceAppt.SelectedAppointmentResources)} to have a {nameof(Resource)}");
if (resourceAppt.SelectedAppointmentResources
.All(r => r.Resource.ParentResourceId != parentResourceId))
throw new Exception(
$"A {nameof(ChildResourceAppointment)} requires at least one of the " +
$"{nameof(resourceAppt.SelectedAppointmentResources)} to have a {nameof(Resource.ParentResourceId)} " +
$"of {parentResourceId}");
}
public DateTime BookedStart => Entity.BookedStart;
public DateTime BookedEnd => Entity.BookedEnd;
public IReadOnlyCollection<SelectedAppointmentResource> SelectedAppointmentResources
=> this.Entity.SelectedAppointmentResources;
public static ChildResourceAppointment From(LocationAppointment locationAppt, Guid parentResourceId)
=> From(locationAppt.ToResourceAppointment(), parentResourceId);
public static ChildResourceAppointment From(ResourceAppointment resourceAppt, Guid parentResourceId)
=> new ChildResourceAppointment(resourceAppt, parentResourceId);
public ResourceAppointment AsResourceAppointment()
=> ResourceAppointment.From(LocationAppointment.From(this.Entity));
}