Exemple #1
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);
            }
        }
Exemple #2
0
        public async Task <Unit> Handle(DeleteFilteredEntitiesCommand <TContext, TEntity> request, CancellationToken cancellationToken)
        {
            var collection = _collectionService.GetCollection <TEntity>();

            var entitiesToDelete = await collection.GetItems(request.Filter);

            if (!entitiesToDelete.Any())
            {
                return(Unit.Value);
            }

            var command = new DeleteEntitiesCommand <TContext>(entitiesToDelete.Cast <object>());

            await _mediator.Send(command);

            return(Unit.Value);
        }