public async Task <IEnumerable <object> > Handle(UpdateEntitiesCommand <TContext> request, CancellationToken cancellationToken)
        {
            try
            {
                var entityType = _commandsHelper.GetEntityType(request.Entities);

                _transactionService.StartTransaction();

                var entityCollection = _transactionService.GetCollection(entityType);
                var edgesCollection  = _transactionService.GetCollection <EntityNode, EntityNodesCollection>();

                await _commandsHelper.VerifyEntities(request.Entities, edgesCollection, SecurityRight.Update);

                await entityCollection.Update(request.Entities);

                _transactionService.CommitTransaction();

                await NotifyEntitiesUpdate(request.Entities);

                return(request.Entities);
            }
            catch (Exception e)
            {
                _transactionService.AbortTransaction();
                throw new EntitiesUpdateException("Entities update failed", e);
            }
        }
        public async Task <IEnumerable <object> > Handle(CreateEntitiesCommand <TContext> request, CancellationToken cancellationToken)
        {
            try
            {
                var entityType = _commandsHelper.GetEntityType(request.Entities);

                _transactionService.StartTransaction();

                var entityCollection = _transactionService.GetCollection(entityType);
                var edgesCollection  = _transactionService.GetCollection <EntityNode, EntityNodesCollection>();

                var parent = await GetParentNode(edgesCollection, request.ParentId);

                var treeEdges = request.Entities
                                .Select(x => CreateTreeEdge(x, parent, entityCollection))
                                .ToList();

                ValidateTreeEdges(edgesCollection, treeEdges);

                await edgesCollection.Add(treeEdges);

                await entityCollection.Add(request.Entities);

                _transactionService.CommitTransaction();

                await NotifyEntitiesCreation(request.Entities, parent);

                return(request.Entities);
            }
            catch (Exception e)
            {
                _transactionService.AbortTransaction();
                throw new EntitiesCreationException("Entities creation failed", e);
            }
        }
Beispiel #3
0
        public async Task <Unit> Handle(DeleteEntitiesCommand <TContext> request, CancellationToken cancellationToken)
        {
            try
            {
                var entityType = _commandsHelper.GetEntityType(request.Entities);
                var nodesId    = _commandsHelper.GetEntitiesId(request.Entities);

                _transactionService.StartTransaction();

                var edgesCollection = _transactionService.GetCollection <EntityNode, EntityNodesCollection>();

                var treeNodes = await _commandsHelper.VerifyEntities(nodesId, edgesCollection, SecurityRight.Delete);

                var deletedNodes = new List <EntityNode>();

                foreach (var treeNode in treeNodes)
                {
                    deletedNodes.AddRange(await DeleteEntityAndDescendants(treeNode, edgesCollection));
                }

                _transactionService.CommitTransaction();

                await NotifyEntitiesDeletion(deletedNodes);

                return(Unit.Value);
            }
            catch (Exception e)
            {
                _transactionService.AbortTransaction();
                throw new EntitiesDeleteException("Entities delete failed", e);
            }
        }