public async Task Handle(ProcessFileAddedEvent message, CancellationToken token) { var caseWorkerTask = ProcessFileAggregate.New(new DomainEvent[] { message }); await _processFileCommandRepository.Add(caseWorkerTask, token); await _processFileCommandRepository.SaveChanges(token); }
public async Task <bool> Handle(UpdateProcessFileCommand request, CancellationToken cancellationToken) { var processFile = await _processFileCommandRepository.Get(request.Id, cancellationToken); if (processFile == null || string.IsNullOrWhiteSpace(processFile.AggregateId)) { _logger.LogError($"Cannot update process file because it doesn't exist : '{request.Id}'"); throw new UnknownProcessFileException(request.Id); } processFile.Update(request.Name, request.Description); await _processFileCommandRepository.Update(processFile, cancellationToken); await _processFileCommandRepository.SaveChanges(cancellationToken); return(true); }
public async Task <CreateProcessFileResult> Handle(CreateProcessFileCommand request, CancellationToken cancellationToken) { var payload = request.Payload; if (string.IsNullOrWhiteSpace(request.Payload)) { payload = _options.DefaultBPMNFile; } var processFile = ProcessFileAggregate.New(Guid.NewGuid().ToString(), request.Name, request.Description, 0, payload); await _processFileCommandRepository.Add(processFile, cancellationToken); await _processFileCommandRepository.SaveChanges(cancellationToken); _logger.LogInformation("Process file has been added"); return(new CreateProcessFileResult { Id = processFile.AggregateId }); }
public async Task <PublishProcessFileResult> Handle(PublishProcessFileCommand request, CancellationToken cancellationToken) { var processFile = await _processFileCommandRepository.Get(request.Id, cancellationToken); if (request == null || string.IsNullOrWhiteSpace(processFile.AggregateId)) { throw new UnknownProcessFileException(request.Id); } var newProcessFile = processFile.Publish(); await _processFileCommandRepository.Update(processFile, cancellationToken); await _processFileCommandRepository.Add(newProcessFile, cancellationToken); await _processFileCommandRepository.SaveChanges(cancellationToken); return(new PublishProcessFileResult { Id = newProcessFile.AggregateId }); }