-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReservation.cs
51 lines (45 loc) · 1.55 KB
/
Reservation.cs
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
41
42
43
44
45
46
47
48
49
50
51
using System.ComponentModel.DataAnnotations.Schema;
using PlayOfferService.Domain.Events;
using PlayOfferService.Domain.Events.Reservation;
namespace PlayOfferService.Domain.Models;
public class Reservation
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid CourtId { get; set; }
public Guid? ReservantId { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public List<Guid>? ParticipantsIds { get; set; } = [];
public bool IsCancelled { get; set; }
public void Apply (List<BaseEvent> baseEvents)
{
foreach (var baseEvent in baseEvents)
{
switch (baseEvent.EventType)
{
case EventType.ReservationCreatedEvent:
ApplyReservationCreatedEvent(baseEvent);
break;
case EventType.ReservationCancelledEvent:
ApplyReservationCancelledEvent();
break;
}
}
}
private void ApplyReservationCancelledEvent()
{
IsCancelled = true;
}
private void ApplyReservationCreatedEvent(BaseEvent baseEvent)
{
var domainEvent = (ReservationCreatedEvent) baseEvent.EventData;
Id = baseEvent.EntityId;
CourtId = domainEvent.CourtId;
ReservantId = domainEvent.ReservantId;
StartTime = domainEvent.Start;
EndTime = domainEvent.End;
ParticipantsIds = domainEvent.ParticipantIds ?? [];
IsCancelled = false;
}
}