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))));
        }
Example #2
0
        private async Task <Dictionary <X, SimpleAggregateData> > GroupAsync <R, X>(IQueryable <long> ids, IQueryable <R> join, Expression <Func <R, X> > keySelector) where R : EntityBase
        {
            var pureList = await provider.GetListAsync(
                ids.Join(join, x => x, r => r.id, (x, r) => r).GroupBy(keySelector).Select(g => new
            {
                key       = g.Key,
                aggregate = new SimpleAggregateData()
                {
                    count     = g.Count(),
                    lastDate  = g.Max(x => x.createDate),
                    firstDate = g.Min(x => x.createDate),
                    lastId    = g.Max(x => x.id)
                }
            })
                );

            pureList.ForEach(x =>
            {
                var kind = DateTime.Now.Kind;

                if (x.aggregate.lastDate != null)
                {
                    x.aggregate.lastDate = new DateTime(((DateTime)x.aggregate.lastDate).Ticks, kind);
                }
                if (x.aggregate.firstDate != null)
                {
                    x.aggregate.firstDate = new DateTime(((DateTime)x.aggregate.firstDate).Ticks, kind);
                }
            });

            return(pureList.ToDictionary(x => x.key, y => y.aggregate));
        }
 public async Task <List <long> > GetRevisionIdsAsync(long packageId)
 {
     return(await provider.GetListAsync(
                from r in await provider.GetQueryableAsync <EntityRelation>()
                where r.entityId1 == packageId && r.type == Keys.HistoryRelation
                select r.entityId2));
 }
        /// <summary>
        /// Link a queryable entity list with values/relations to produce a list of packaged entities
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="queryable"></param>
        /// <returns></returns>
        public static async Task <List <EntityPackage> > LinkAsync(this IEntityProvider provider, IQueryable <Entity> queryable)
        {
            //Performance test this sometime
            var entities = await provider.GetListAsync(queryable);

            //Oops, there's nothing. Don't bother (we don't need to query the WHOLE database for no entities)
            if (entities.Count == 0)
            {
                return(new List <EntityPackage>());
            }

            var ids    = entities.Select(x => x.id).ToList();
            var values = await provider.GetEntityValuesAsync(new EntityValueSearch()
            {
                EntityIds = ids
            });                                                                                            //Will this stuff be safe?

            var relations = await provider.GetEntityRelationsAsync(new EntityRelationSearch()
            {
                EntityIds2 = ids
            });                                                                                                      //Will this stuff be safe?

            return(entities.Select(x => new EntityPackage()
            {
                Entity = x,
                Values = values.Where(y => y.entityId == x.id).ToList(),
                Relations = relations.Where(y => y.entityId2 == x.id).ToList()
            }).ToList());
        }
Example #5
0
 public virtual async Task <ActionResult <IEnumerable <TEntity> > > Get()
 {
     return(Ok(await _entityProvider.GetListAsync()));
 }