Ejemplo n.º 1
0
        public async Task <List <Post> > GetReplies(RepliesSortType sortType, int parentId, int?directReplyLimit, int?directReplyOffset, int startDepth, int depthLimit, int recursiveLimit)
        {
            using (var conn = this.Connection)
            {
                conn.Open();

                PostgresqlParameters param = new PostgresqlParameters();
                param.Add("@input_parent_id", parentId);
                param.Add("@direct_reply_limit", directReplyLimit);   // null will retrieve all
                param.Add("@direct_reply_offset", directReplyOffset); // null will offset none
                param.Add("@start_depth", startDepth);
                param.Add("@depth_limit", depthLimit);
                param.Add("@recursive_limit", recursiveLimit);

                IEnumerable <Post> results;
                switch (sortType)
                {
                case RepliesSortType.Top:
                    results = await conn.QueryAsync <Post>("get_replies_top", param, null, null, CommandType.StoredProcedure);

                    break;

                default:
                    results = await conn.QueryAsync <Post>("get_replies_best", param, null, null, CommandType.StoredProcedure);

                    break;
                }

                return(results.ToList());
            }
        }
Ejemplo n.º 2
0
        public async Task <List <Post> > LoadSubPostReplies(RepliesSortType sortType, int parentId, int startDepth, int maxDepth, int offset)
        {
            if (startDepth > maxDepth)
            {
                // return error saying you cannot start past MaxDepth
                throw new ArgumentException($"Start Depth of {startDepth} must be less than the Max-Depth of {maxDepth}");
            }

            // return all replies to sub-post, off-set to start after the last comment returned. startDepth ensures we start at the same depth as we left off
            return(await GetReplies(sortType, parentId, directReplyLimit : null, directReplyOffset : offset, startDepth : startDepth, depthLimit : maxDepth, recursiveLimit : 1));
        }
Ejemplo n.º 3
0
        private async Task <List <Post> > GetReplies(RepliesSortType sortType, int rootPostId, int?directReplyLimit, int?directReplyOffset, int startDepth, int depthLimit, int recursiveLimit)
        {
            var rootPost = await this.postsRepository.GetRootPost(rootPostId);

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

            List <Post> repliesToRootPost = new List <Post>();

            repliesToRootPost = await this.postsRepository.GetReplies(sortType, rootPostId, directReplyLimit, directReplyOffset, startDepth, depthLimit, recursiveLimit);

            var repliesTree = BuildTree(repliesToRootPost, startDepth, depthLimit);

            return(repliesTree);
        }
Ejemplo n.º 4
0
 public async Task <List <Post> > LoadRootPostReplies(RepliesSortType sortType, int rootPostId, int maxDepth)
 {
     // return top 100 comments to root-post, then go until max depth in with top 10 replies
     return(await GetReplies(sortType, rootPostId, directReplyLimit : 100, directReplyOffset : null, startDepth : 0, depthLimit : maxDepth, recursiveLimit : 10));
 }
Ejemplo n.º 5
0
 public async Task <ActionResult <List <Post> > > GetSubPostReplies(RepliesSortType sortType, int parentId, int startDepth, int maxDepth, int offSet)
 {
     return(await this.postTreeService.LoadSubPostReplies(sortType, parentId, startDepth, maxDepth, offSet));
 }
Ejemplo n.º 6
0
 public async Task <ActionResult <List <Post> > > GetRootPostReplies(RepliesSortType sortType, int rootPostId, int maxDepth)
 {
     return(await this.postTreeService.LoadRootPostReplies(sortType, rootPostId, maxDepth));
 }