Esempio n. 1
0
        public async Task Handle(CasePlanInstanceCreatedEvent message, CancellationToken token)
        {
            var record = CasePlanInstanceAggregate.New(new List <DomainEvent> {
                message
            });
            await _casePlanInstanceCommandRepository.Add(record, token);

            await _casePlanInstanceCommandRepository.SaveChanges(token);
        }
        public async Task <CasePlanInstanceResult> Handle(CreateCaseInstanceCommand request, CancellationToken cancellationToken)
        {
            var workflowDefinition = await _casePlanCommandRepository.Get(request.CasePlanId, cancellationToken);

            if (workflowDefinition == null)
            {
                throw new UnknownCasePlanException(request.CasePlanId);
            }

            var casePlanInstance = CasePlanInstanceAggregate.New(Guid.NewGuid().ToString(), workflowDefinition, request.NameIdentifier, request.Parameters);
            await _casePlanInstanceCommandRepository.Add(casePlanInstance, cancellationToken);

            await _casePlanInstanceCommandRepository.SaveChanges(cancellationToken);

            await _busControl.Publish(casePlanInstance.DomainEvents.First(s => s is CasePlanInstanceCreatedEvent) as CasePlanInstanceCreatedEvent, cancellationToken);

            return(CasePlanInstanceResult.ToDto(casePlanInstance));
        }