Example #1
0
        async Task <TEntityReply> EntityReplyUpdated(TEntityReply reply)
        {
            // Get all tags for reply
            var replyTags = await _entityTagStore.QueryAsync()
                            .Select <EntityTagQueryParams>(q =>
            {
                q.EntityReplyId.Equals(reply.Id);
            })
                            .ToList();

            // No tags for reply just continue
            if (replyTags?.Data == null)
            {
                return(reply);
            }

            // Update counts for all tags associated with reply
            foreach (var replyTag in replyTags.Data)
            {
                await _tagOccurrencesUpdater.UpdateAsync(replyTag.ConvertToType <TTag>());
            }

            // return
            return(reply);
        }
Example #2
0
        async Task <IDictionary <int, IList <EntityTag> > > BuildLookUpTable()
        {
            // Get index view model from context
            var viewModel = _actionContextAccessor.ActionContext.HttpContext.Items[typeof(EntityIndexViewModel <Doc>)] as EntityIndexViewModel <Doc>;

            if (viewModel == null)
            {
                return(null);
            }

            // We need results
            if (viewModel.Results == null)
            {
                return(null);
            }

            // Get all entities for our current view
            var entities = viewModel.Results;

            // Get all entity tag relationships for displayed entities
            IPagedResults <EntityTag> entityTags = null;

            if (entities?.Data != null)
            {
                entityTags = await _entityTagStore.QueryAsync()
                             .Take(int.MaxValue, false)
                             .Select <EntityTagQueryParams>(q =>
                {
                    q.EntityId.IsIn(entities.Data.Select(e => e.Id).ToArray());
                    q.EntityReplyId.Equals(0);
                })
                             .ToList();
            }

            // Build a dictionary of entity and tag relationships
            var output = new ConcurrentDictionary <int, IList <EntityTag> >();

            if (entityTags?.Data != null)
            {
                foreach (var entityTag in entityTags.Data)
                {
                    var tag = entityTags.Data.FirstOrDefault(t => t.TagId == entityTag.TagId);
                    if (tag != null)
                    {
                        tag.Id = tag.TagId;
                        output.AddOrUpdate(entityTag.EntityId, new List <EntityTag>()
                        {
                            tag
                        }, (k, v) =>
                        {
                            v.Add(tag);
                            return(v);
                        });
                    }
                }
            }

            return(output);
        }
Example #3
0
        public async Task UpdateAsync(TModel tag)
        {
            // Get count for public entities & replies tagged with this tag
            var entityTags = await _entityTagStore.QueryAsync()
                             .Take(1)
                             .Select <EntityTagQueryParams>(q =>
            {
                q.TagId.Equals(tag.Id);
                q.HideHidden.True();
                q.HidePrivate.True();
                q.HideSpam.True();
                q.HideDeleted.True();
            })
                             .ToList();

            // Update
            tag.TotalEntities = entityTags?.Total ?? 0;

            // Persist
            await _tagManager.UpdateAsync(tag);
        }