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);
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <TEntity> > Handle(PartialUpdateEntitiesCommand <TContext, TEntity, TField> request, CancellationToken cancellationToken)
        {
            try
            {
                _transactionService.StartTransaction();

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

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

                await entityCollection.Update <TField>(request.Entities, request.Field, request.Value);

                _transactionService.CommitTransaction();

                var entities = await entityCollection.GetItems(request.Entities);

                await NotifyEntitiesUpdate(entities);

                return(entities);
            }
            catch (Exception e)
            {
                _transactionService.AbortTransaction();
                throw new EntitiesUpdateException("Entities update 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);
            }
        }