public BaseCasePlanItemInstance TryCreateInstance(BaseCasePlanItemInstance elt) { var evt = new CasePlanItemInstanceCreatedEvent(Guid.NewGuid().ToString(), AggregateId, Version, elt.Id, DateTime.UtcNow); Handle(evt); DomainEvents.Add(evt); var id = BaseCasePlanItemInstance.BuildId(AggregateId, elt.EltId, elt.NbOccurrence + 1); return(GetCasePlanItem(id)); }
private void Handle(CasePlanItemInstanceCreatedEvent evt) { var parent = GetCasePlanItemParent(evt.CasePlanItemInstanceId); if (parent == null) { throw new AggregateValidationException(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("validation", $"case plan item '{evt.CasePlanItemInstanceId}' doesn't exist") }); } var child = GetCasePlanItem(evt.CasePlanItemInstanceId); parent.Children.Add(child.NewOccurrence(AggregateId)); }