public Task Add(TItem entity)
        {
            var id = _propertyResolver.GetEntityId(entity);

            lock (this)
            {
                if (_innerDict.ContainsKey(id))
                {
                    throw new InvalidOperationException($"Element {id} already present");
                }

                _innerDict.Add(id, entity);
                return(Task.FromResult(true));
            }
        }
        private EntityNode CreateTreeEdge(object entity, EntityNode parent, IGodzillaCollection entityCollection)
        {
            var entityId   = _propertyResolver.GetEntityId(entity, true);
            var entityName = _propertyResolver.GetEntityName(entity);

            return(new EntityNode
            {
                Id = Guid.NewGuid(),
                EntityId = entityId,
                NodeName = entityName,
                ParentId = parent?.EntityId ?? Guid.Empty,
                CollectionId = entityCollection.CollectionId,
                Path = _commandsHelper.BuildNamePath(entityName, parent),
                IdPath = _commandsHelper.BuildIdPath(entityId, parent),
            });
        }
Example #3
0
        public async Task <TParent> GetParent <TParent>(object entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var nodesCollection = GetEntityNodesCollection();
            var itemId          = _propertyResolver.GetEntityId(entity);
            var itemNode        = nodesCollection.GetNode(itemId);

            var parentEntityId     = itemNode.ParentId;
            var parentCollection   = GetCollection <TParent>();
            var parentCollectionId = parentCollection.CollectionId;

            var parentNode = nodesCollection
                             .AsQueryable()
                             .FirstOrDefault(x =>
                                             x.EntityId == parentEntityId &&
                                             x.CollectionId == parentCollectionId);

            if (itemNode == null || itemNode.ParentId == Guid.Empty)
            {
                return(default(TParent));
            }

            var filteredNodes = await FilterAllowedNodes(new List <Guid> {
                itemNode.ParentId
            });

            if (!filteredNodes.Any())
            {
                return(default(TParent));
            }

            return(await parentCollection.GetItem(filteredNodes.First()));
        }
 public async Task Update(TItem entity)
 {
     var id = _propertyResolver.GetEntityId(entity);
     await _collection.ReplaceOneAsync(GetEntityIdFilter(id), entity);
 }
Example #5
0
        public async Task <IEnumerable <TEntity> > Add <TEntity>(IEnumerable <TEntity> entities, object parent)
        {
            var parentId = _propertyResolver.GetEntityId(parent);

            return(await Add(entities, parentId));
        }
Example #6
0
 public Guid GetEntityId(object entity)
 {
     return(_propertyResolver.GetEntityId(entity, false));
 }