public void Handle(CreateUseCaseDiagramCommand command) { var id = Guid.NewGuid(); var projectId = _currentProjectContextId.Get(); if (projectId == null) { throw new Exception(Sentences.noProjectInContext); } var package = _packageRepository.Get(command.PackageId.Value); if (!package.Active) { throw new Exception(Sentences.thisPackageWasRemoved); } var nextId = _useCaseDiagramNextIdQueryHandler.Handle(projectId.Value); var specificationItem = new SpecificationItem(); specificationItem.Id = id; specificationItem.Active = true; specificationItem.Type = SpecificationItemType.UseCaseDiagram; specificationItem.PackageId = command.PackageId.Value; specificationItem.Label = $"UCD{nextId}"; var useCaseDiagram = new UseCaseDiagram(); useCaseDiagram.Id = id; useCaseDiagram.SpecificationItem = specificationItem; useCaseDiagram.ProjectId = projectId.Value; useCaseDiagram.Version = 1; useCaseDiagram.IsLastVersion = true; useCaseDiagram.Identifier = nextId; _useCaseDiagramItemsPersister.Persist(useCaseDiagram, command); _useCaseDiagramRepository.Add(useCaseDiagram); _specifiationItemRepository.Add(specificationItem); }
public void Handle(CreateUseCaseDiagramNewVersionCommand command) { var queryResult = _specificationItemWithUseCaseDiagramsQueryHandler.Handle(command.Id.Value); var latestVersion = queryResult.UseCaseDiagrams.FirstOrDefault(s => s.IsLastVersion); foreach (var oldUseCaseDiagramsVersion in queryResult.UseCaseDiagrams) { oldUseCaseDiagramsVersion.IsLastVersion = false; } var oldUseCasesVersions = _useCasesByDiagramQueryHandler.Handle(command.Id); foreach (var oldUseCaseVersion in oldUseCasesVersions) { oldUseCaseVersion.IsLastVersion = false; } var package = _packageRepository.Get(command.PackageId.Value); if (!package.Active) { throw new Exception(Sentences.thisPackageWasRemoved); } var useCaseDiagram = new UseCaseDiagram(); useCaseDiagram.Id = command.Id.Value; useCaseDiagram.SpecificationItem = queryResult.SpecificationItem; useCaseDiagram.SpecificationItem.PackageId = package.Id; useCaseDiagram.ProjectId = latestVersion.ProjectId; useCaseDiagram.Version = latestVersion.Version + 1; useCaseDiagram.Identifier = latestVersion.Identifier; useCaseDiagram.IsLastVersion = true; RetrieveSpecificationItemIdsForCommandUseCases(command, oldUseCasesVersions); _useCaseDiagramItemsPersister.Persist(useCaseDiagram, command, oldUseCasesVersions); _useCaseDiagramRepository.Add(useCaseDiagram); }