public static async Task <EntityRelation> FindRelationByIdAsync(this IEntityProvider provider, long id)
        {
            var search = new EntityRelationSearch();

            search.Ids.Add(id);
            return((await provider.GetEntityRelationsAsync(search)).OnlySingle());
        }
 public Task <List <EntityRelation> > GetEntityRelationsAsync(EntityRelationSearch search)
 {
     logger.LogTrace("GetEntityRelationsAsync called");
     return(LockAsync(async() =>
     {
         var relations = await query.GetQueryableAsync <EntityRelation>();
         return await query.GetListAsync(searcher.ApplyEntityRelationSearch(relations, search));
     }));
 }
예제 #3
0
        public async Task <List <B> > GetBasicAsync(S search)
        {
            var entitySearch = mapper.Map <EntitySearch>(search);

            entitySearch.TypeLike = keys[EntityType];

            List <long> searchIds = new List <long>();

            foreach (var transfer in TransferValues)
            {
                var fieldSearch = transfer.Value.SearchRetrieve(search);

                if (!string.IsNullOrEmpty(fieldSearch))
                {
                    var valueSearch = new EntityValueSearch()
                    {
                        KeyLike = keys[transfer.Key], ValueLike = fieldSearch
                    };
                    searchIds = AndedSearch(searchIds, (await provider.GetEntityValuesAsync(valueSearch)).Select(x => x.entityId));
                    if (searchIds.Count == 0)
                    {
                        return(new List <B>());
                    }
                }
            }

            foreach (var transfer in TransferRelations)
            {
                var fieldSearch = transfer.Value.SearchRetrieve(search);

                if (fieldSearch > 0)
                {
                    var relationSearch = new EntityRelationSearch()
                    {
                        TypeLike = keys[transfer.Key]
                    };
                    relationSearch.EntityIds1.Add(fieldSearch);
                    searchIds = AndedSearch(searchIds, (await provider.GetEntityRelationsAsync(relationSearch)).Select(x => x.entityId2));
                    if (searchIds.Count == 0)
                    {
                        return(new List <B>());
                    }
                }
            }

            entitySearch.Ids.AddRange(searchIds);

            var results = await provider.GetEntitiesAsync(entitySearch);

            return(results.Select(x => mapper.Map <B>(x)).ToList());
        }
예제 #4
0
        public async Task <List <EntityRelationPackage> > LinkAsync(IEnumerable <EntityRelation> relations)
        {
            //This finds historical data (if there is any, it's probably none every time)
            var secondarySearch = new EntityRelationSearch();

            secondarySearch.EntityIds1 = relations.Select(x => - x.id).ToList();

            var historyRelations = await provider.GetEntityRelationsAsync(secondarySearch);

            return(relations.Select(x => new EntityRelationPackage()
            {
                Main = x,
                Related = historyRelations.Where(y => y.entityId1 == -x.id).ToList()
            }).ToList());
        }
        public virtual async Task <List <EntityRelationPackage> > LinkAsync(List <EntityRelation> relations)
        {
            if (relations.Count > 0)
            {
                var secondarySearch = new EntityRelationSearch();
                secondarySearch.EntityIds1 = relations.Select(x => - x.id).ToList();

                var historyRelations = await services.provider.GetEntityRelationsAsync(secondarySearch);

                return(relations.Select(x => new EntityRelationPackage()
                {
                    Main = x,
                    Related = historyRelations.Where(y => y.entityId1 == -x.id).ToList()
                }).ToList());
            }
            else
            {
                return(new List <EntityRelationPackage>()); //NOTHING
            }
        }
 public IQueryable <EntityRelation> ApplyEntityRelationSearch(IQueryable <EntityRelation> query, EntityRelationSearch search, bool finalize)
 {
     return(searcher.ApplyEntityRelationSearch(query, search, finalize));
 }
예제 #7
0
        public IQueryable <EntityRelation> ApplyEntityRelationSearch(IQueryable <EntityRelation> query, EntityRelationSearch search, bool finalize)
        {
            query = ApplyGeneric <EntityRelation>(query, search, false);

            if (!string.IsNullOrEmpty(search.TypeLike))
            {
                query = query.Where(x => EF.Functions.Like(x.type, search.TypeLike));
            }

            if (search.Types.Count > 0)
            {
                query = query.Where(x => search.Types.Contains(x.type));
            }

            if (search.EntityIds1.Count > 0)
            {
                query = query.Where(x => search.EntityIds1.Contains(x.entityId1));
            }

            if (search.EntityIds2.Count > 0)
            {
                query = query.Where(x => search.EntityIds2.Contains(x.entityId2));
            }

            if (finalize)
            {
                query = ApplyFinal(query, search);
            }

            return(query);
        }