Exemplo n.º 1
0
        public IQueryable <T> GetByTag <T>([NotNull] string tagName, long?projectId)
            where T : class, IEntity
        {
            var tag = _tagProvider.Get(tagName);

            var dataSource = _tagDataSourceProvider.Get <T>(projectId);

            var tagEntities = tag.TagEntities
                              .Where(_ => _.TableId == dataSource.Id)
                              .Select(_ => _.EntityId);

            var entityRepository = _tagEntityRepositoryProvider.Get <T>();

            return(entityRepository.Query().Where(_ => tagEntities.Contains(_.Id)));
        }
        public void Add <T>([NotNull] T entity, [NotNull] Tags tag) where T : class, IEntity
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            var dataSource = _tagDataSourceProvider.Get(entity);

            var tagEntity = new TagEntities
            {
                EntityId = entity.Id,
                TableId  = dataSource.Id,
                TagId    = tag.Id
            };

            _tagEntityRepository.Insert(tagEntity);

            _tagEntityRepository.Save();
        }