/// <summary>
        /// Find a value by key/value/id (added constraints)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <EntityValue> FindValueAsync(string type, string key, string value = null, long id = -1) //long.MinValue)
        {
            var valueSearch = new EntityValueSearch()
            {
                KeyLike = key
            };

            if (value != null)
            {
                valueSearch.ValueLike = value;
            }
            if (id > 0)
            {
                valueSearch.EntityIds.Add(id);
            }

            var values = await provider.GetQueryableAsync <EntityValue>();

            var entities = await provider.GetQueryableAsync <Entity>();

            var thing =
                from v in provider.ApplyEntityValueSearch(values, valueSearch)
                join e in entities on v.entityId equals e.id
                where EF.Functions.Like(e.type, $"{type}%")
                select v;

            return((await provider.GetListAsync(thing)).OnlySingle());
        }
Ejemplo n.º 2
0
        public async Task <UserGroupHideData> GetUserHideDataAsync(IEnumerable <long> users)
        {
            UserGroupHideData result = null;
            var search = new EntityValueSearch()
            {
                EntityIds = users.Distinct().OrderBy(x => x).ToList(), KeyLike = Keys.UserHideKey
            };
            var key = string.Join(",", search.EntityIds);

            if (hidecache.GetValue(key, ref result))
            {
                return(result);
            }
            result = new UserGroupHideData()
            {
                hides = (await provider.GetEntityValuesAsync(search)).Select(x =>
                                                                             new UserHideData()
                {
                    userId = x.entityId,
                    hides  = x.value.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList()
                }).ToList()
            };
            hidecache.StoreItem(key, result);
            return(result);
        }
Ejemplo n.º 3
0
 public Task <List <EntityValue> > GetEntityValuesAsync(EntityValueSearch search)
 {
     logger.LogTrace("GetEntityValuesAsync called");
     return(LockAsync(async() =>
     {
         var values = await query.GetQueryableAsync <EntityValue>();
         return await query.GetListAsync(searcher.ApplyEntityValueSearch(values, search));
     }));
 }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <List <string> > > GetAsync()
        {
            var search = new EntityValueSearch()
            {
                KeyLike = Keys.VariableKey + "%",
            };

            search.EntityIds.Add(-GetRequesterUid());

            var baseValues   = provider.GetQueryable <EntityValue>();
            var searchValues = provider.ApplyEntityValueSearch(baseValues, search);

            return(await provider.GetListAsync(searchValues.Select(x => x.key.Substring(Keys.VariableKey.Length))));
        }
Ejemplo n.º 6
0
 public IQueryable <EntityValue> ApplyEntityValueSearch(IQueryable <EntityValue> query, EntityValueSearch search, bool finalize)
 {
     return(searcher.ApplyEntityValueSearch(query, search, finalize));
 }
Ejemplo n.º 7
0
        public IQueryable <EntityValue> ApplyEntityValueSearch(IQueryable <EntityValue> query, EntityValueSearch search, bool finalize)
        {
            query = ApplyGeneric(query, search, false);

            if (!string.IsNullOrEmpty(search.KeyLike))
            {
                query = query.Where(x => EF.Functions.Like(x.key, search.KeyLike));
            }
            if (!string.IsNullOrEmpty(search.ValueLike))
            {
                query = query.Where(x => EF.Functions.Like(x.value, search.ValueLike));
            }

            if (search.Values.Count > 0)
            {
                query = query.Where(x => search.Values.Contains(x.value));
            }
            if (search.Keys.Count > 0)
            {
                query = query.Where(x => search.Keys.Contains(x.key));
            }

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

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

            return(query);
        }