示例#1
0
        public async Task <IPagedResults <TModel> > GetResultsAsync(EntityOptions options, PagerOptions pager)
        {
            // Build sort columns from model
            var sortColumns = new Dictionary <string, OrderBy>();

            if (options.SortColumns != null)
            {
                foreach (var column in options.SortColumns)
                {
                    sortColumns.Add(column.Key, column.Value);
                }
            }
            else
            {
                sortColumns.Add(options.Sort, options.Order);
            }

            return(await _entityReplyStore.QueryAsync()
                   .Take(pager.Page, pager.Size)
                   .Configure(_configureDb)
                   .Select <EntityReplyQueryParams>(q =>
            {
                q.EntityId.Equals(options.Id);

                // Additional parameter configuration
                _configureParams?.Invoke(q);
            })
                   .OrderBy(sortColumns)
                   .ToList());
        }
示例#2
0
 async Task <IPagedResults <TEntityReply> > GetReplies(Entity entity)
 {
     return(await _entityReplyStore.QueryAsync()
            .Select <EntityReplyQueryParams>(q =>
     {
         q.EntityId.Equals(entity.Id);
         q.HideHidden.True();
         q.HideSpam.True();
         q.HideDeleted.True();
     })
            .OrderBy("CreatedDate", OrderBy.Desc)
            .ToList());
 }
示例#3
0
        async Task <TEntityReply> UpdateEntityDetailsAsync(TEntityReply reply)
        {
            // Get entity
            var entity = await _entityStore.GetByIdAsync(reply.EntityId);

            if (entity == null)
            {
                return(reply);
            }

            // Get latest reply & total reply count
            var replies = await _entityReplyStore.QueryAsync()
                          .Take(1)
                          .Select <EntityReplyQueryParams>(q =>
            {
                q.EntityId.Equals(entity.Id);
                q.HideHidden.True();
                q.HideSpam.True();
                q.HideDeleted.True();
            })
                          .OrderBy("CreatedDate", OrderBy.Desc)
                          .ToList();

            TEntityReply lastReply = null;
            int          totalReplies = 0, totalParticipants = 0;

            if (replies?.Data != null)
            {
                totalReplies      = replies.Total;
                totalParticipants = GetTotalUniqueParticipantCount(replies.Data);
                lastReply         = replies.Data[0];
            }

            // Update last reply
            entity.TotalReplies      = totalReplies;
            entity.TotalParticipants = totalParticipants;
            entity.LastReplyId       = lastReply?.Id ?? 0;
            entity.LastReplyUserId   = lastReply?.CreatedUserId ?? 0;
            entity.LastReplyDate     = lastReply?.CreatedDate ?? null;

            // Persist the updates
            await _entityStore.UpdateAsync(entity);

            return(reply);
        }
示例#4
0
        async Task <Question> UpdateEntityAsync(Question entity)
        {
            // Get a total count of all replies marked as an answer
            var answers = await _entityReplyStore.QueryAsync()
                          .Take(1)
                          .Select <EntityReplyQueryParams>(q =>
            {
                q.EntityId.Equals(entity.Id);
                q.ShowAnswers.True();
            })
                          .ToList();

            // Update answer details on entity
            entity.TotalAnswers = answers?.Total ?? 0;

            // Update entity
            return(await _entityStore.UpdateAsync(entity));
        }
示例#5
0
        public async Task UpdateAsync(int categoryId)
        {
            // Get supplied category and all parent categories
            var parents = await _channelStore.GetParentsByIdAsync(categoryId);

            // Update details within current and all parents
            foreach (var parent in parents)
            {
                // Get all children for current category
                var children = await _channelStore.GetChildrenByIdAsync(parent.Id);

                // Get latest topic & total topic count for current channel
                var topics = await _topicStore.QueryAsync()
                             .Take(1) // we only need the latest topic but need a total count
                             .Select <EntityQueryParams>(q =>
                {
                    // Include entities from child channels?
                    if (children != null)
                    {
                        var channelIds = children
                                         .Select(c => c.Id)
                                         .Append(parent.Id)
                                         .ToArray();
                        q.CategoryId.IsIn(channelIds);
                    }
                    else
                    {
                        // Get topics for current channel
                        q.CategoryId.Equals(parent.Id);
                    }

                    q.HidePrivate.True();
                    q.HideHidden.True();
                    q.HideSpam.True();
                    q.HideDeleted.True();
                })
                             .OrderBy("LastReplyDate", OrderBy.Desc)
                             .ToList();

                // Get latest reply & total reply count for current channel
                var replies = await _replyStore.QueryAsync()
                              .Take(1, 1, true)
                              .Select <EntityReplyQueryParams>(q =>
                {
                    // Include entities from child channels?
                    if (children != null)
                    {
                        var channelIds = children
                                         .Select(c => c.Id)
                                         .Append(parent.Id)
                                         .ToArray();
                        q.CategoryId.IsIn(channelIds);
                    }
                    else
                    {
                        // Get topics for current channel
                        q.CategoryId.Equals(parent.Id);
                    }

                    q.HideHidden.True();
                    q.HideSpam.True();
                    q.HideDeleted.True();
                })
                              .OrderBy("CreatedDate", OrderBy.Desc)
                              .ToList();

                var   totalEntities = 0;
                Topic latestEntity  = null;
                if (topics?.Data != null)
                {
                    totalEntities = topics.Total;
                    latestEntity  = topics.Data[0];
                }

                var   totalReplies = 0;
                Reply latestReply  = null;
                if (replies?.Data != null)
                {
                    totalReplies = replies.Total;
                    latestReply  = replies.Data[0];
                }

                // Update channel details with latest entity details
                var details = parent.GetOrCreate <CategoryDetails>();
                details.TotalEntities = totalEntities;
                details.TotalReplies  = totalReplies;

                if (latestEntity != null)
                {
                    details.LatestEntity = new LatestPost
                    {
                        Id          = latestEntity.Id,
                        Alias       = latestEntity.Alias,
                        CreatedBy   = latestEntity.CreatedBy,
                        CreatedDate = latestEntity.CreatedDate
                    };
                }
                else
                {
                    details.LatestEntity = null;
                }

                if (latestReply != null)
                {
                    details.LatestReply = new LatestPost
                    {
                        Id          = latestReply.Id,
                        CreatedBy   = latestReply.CreatedBy,
                        CreatedDate = latestReply.CreatedDate
                    };
                }
                else
                {
                    details.LatestReply = null;
                }

                parent.AddOrUpdate <CategoryDetails>(details);

                // Save the updated details
                await _channelManager.UpdateAsync(parent);
            }
        }