public bool TryAddWorkerTask(string casePlanInstanceElementId) { var workerTask = WorkerTasks.FirstOrDefault(_ => _.CasePlanElementInstanceId == casePlanInstanceElementId); if (workerTask != null) { return(false); } var evt = new CaseInstanceWorkerTaskAddedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, casePlanInstanceElementId, DateTime.UtcNow, CaseOwnerRole); Handle(evt); DomainEvents.Add(evt); return(true); }
private void Handle(CaseInstanceWorkerTaskRemovedEvent evt) { var workertask = WorkerTasks.FirstOrDefault(_ => _.CasePlanElementInstanceId == evt.CasePlanInstanceElementId); if (workertask == null) { throw new AggregateValidationException(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("validation", $"case worker task doesn't exist '{workertask.CasePlanElementInstanceId}'") }); } WorkerTasks.Remove(workertask); Version = evt.Version; UpdateDateTime = evt.ExecutionDateTime; }
public void MakeTransition(BaseCaseEltInstance element, CMMNTransitions transition, bool isEvtPropagate = true) { var evt = new CaseElementTransitionRaisedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, element.Id, transition, DateTime.UtcNow); Handle(evt); DomainEvents.Add(evt); var caseWorkerTask = WorkerTasks.FirstOrDefault(_ => _.CasePlanElementInstanceId == element.Id); if (caseWorkerTask != null && (transition == CMMNTransitions.Complete || transition == CMMNTransitions.Terminate || transition == CMMNTransitions.ParentTerminate)) { var removeCWT = new CaseInstanceWorkerTaskRemovedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, element.Id, DateTime.UtcNow); Handle(removeCWT); DomainEvents.Add(removeCWT); } if (isEvtPropagate) { PropagateTransition(element, transition); } }