Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }