private async Task <List <APEntity> > _search(Dictionary <string, string> lookFor, int?inCollectionId = null) { var attributeMapping = new Dictionary <int, int>(); foreach (var val in lookFor) { var reverseId = await _entityStore.ReverseAttribute(val.Key, false); if (reverseId == null) { return(new List <APEntity>()); } var reverseVal = await _entityStore.ReverseAttribute(val.Value, false); if (reverseVal == null) { return(new List <APEntity>()); } attributeMapping[reverseId.Value] = reverseVal.Value; } var start = $"select a.* from \"TripleEntities\" a where "; start += string.Join(" and ", attributeMapping.Select(a => $"exists(select 1 from \"Triples\" where \"PredicateId\" = {a.Key} and \"AttributeId\" = {a.Value} and \"SubjectId\" = a.\"IdId\" and \"SubjectEntityId\" = a.\"EntityId\")")); if (inCollectionId != null) { start += $" and exists(select 1 from \"CollectionItems\" where \"CollectionId\" = {inCollectionId} and \"CollectionItemId\" = a.\"EntityId\")"; } return(await _entityStore.GetEntities((await _connection.QueryAsync <APTripleEntity>(start)).Select(a => a.EntityId).ToList())); }
public async Task <List <EntityCollectionItem> > GetItems(string id, int fromId = int.MaxValue, int toId = int.MinValue, int count = 10, RelevantEntitiesService.IQueryStatement query = null) { var isOwner = false; var entity = await _entityStore.GetEntity(id, false); var user = _getUser(); if (entity != null && entity.Data["attributedTo"].Any(a => a.Id == user)) { isOwner = true; } var entities = await _filterAudience(user, isOwner, entity.DbId, count, fromId, toId, query); return((await _entityStore.GetEntities(entities.Select(a => a.ElementId).ToList())).Zip(entities, (a, b) => new EntityCollectionItem { CollectionItemId = b.CollectionItemId, Entity = a }).ToList()); }