示例#1
0
        //get topics on paging
        public PageListClient <TopicClient> PagingClientTopics(int pageSize, PageTopicFilterClient filter)
        {
            Expression <Func <ContentTopic, bool> > predicate = PredicateBuilder.True <ContentTopic>(); // null; // = x => x.IsVisible == false;

            predicate = predicate.And(x => !x.IsHidden);

            //Ignore it, if there is only one thread in the system
            if (_threadWork.TotalThreadCount > 1)
            {
                ContentThread thread = _threadWork.GetThread(filter.ThreadKey);
                Expression <Func <ContentTopic, bool> > threadPredicate = PredicateBuilder.False <ContentTopic>();
                threadPredicate = threadPredicate.Or(x => x.ThreadId == thread.Id);
                predicate       = predicate.And(threadPredicate.Expand());
            }

            foreach (var tagOption in filter.TagOptions)
            {
                if (string.IsNullOrEmpty(tagOption.IdStrs) || tagOption.IdStrs.Contains(WebConstants.Tag_Specifier_All))
                {
                    continue;
                }
                List <Guid> tagIds = tagOption.ToTagIds();
                if (tagIds.Count > 0)
                {
                    Expression <Func <ContentTopic, bool> > singleTagPredicate = PredicateBuilder.False <ContentTopic>();
                    foreach (var tagId in tagIds)
                    {
                        singleTagPredicate = singleTagPredicate.Or(x => x.Tags.Select(t => t.Id).Contains(tagId));
                    }

                    if (singleTagPredicate != null)
                    {
                        predicate = predicate.And(singleTagPredicate.Expand()); //call expand() to fix not bound error
                    }
                }
            }

            var pageTopic = _topicWork.Paging(filter.PageNumber, pageSize, filter.Sort, predicate, new string[] { "Tags" });
            PageListClient <TopicClient> page = new PageListClient <TopicClient>(pageTopic, pageTopic.Count);

            foreach (var topic in pageTopic)
            {
                page.Add(ToClient(topic, excludeProperties: new string[] { "Tags", "FirstComment", "Comments", "UploadPermission" }));
            }

            return(page);
        }
示例#2
0
        public PageListClient <TopicClient> PagingMyClientTopics(int pageNumber, int pageSize, string sort)
        {
            Expression <Func <ContentTopic, bool> > predicate = PredicateBuilder.True <ContentTopic>();

            predicate = predicate.And(x => x.UserId == SecurityManager.CurrentUser.UserId);
            predicate = predicate.Expand();

            var pageTopic = _topicWork.Paging(pageNumber, pageSize, sort, predicate);
            PageListClient <TopicClient> page = new PageListClient <TopicClient>(pageTopic, pageTopic.Count);

            foreach (var topic in pageTopic)
            {
                page.Add(ToClient(topic, excludeProperties: new string[] { "Tags", "Comments", "UploadPermission" }));
            }

            return(page);
        }
示例#3
0
        public PageListClient <CommentClient> PagingMyClientComments(int pageNumber, int pageSize, string sort)
        {
            Expression <Func <ContentComment, bool> > predicate = PredicateBuilder.True <ContentComment>();

            predicate = predicate.And(x => x.UserId == SecurityManager.CurrentUser.UserId);
            predicate = predicate.Expand();

            var pageComments = _commentWork.Paging(pageNumber, pageSize, sort, predicate, new string[] { "Topic" });
            PageListClient <CommentClient> page = new PageListClient <CommentClient>(pageComments, pageComments.Count);

            foreach (var comment in pageComments)
            {
                page.Add(ToClient(comment, excludeProperties: new string[] { "Vote", "Topic.SubTitle" }));
            }

            return(page);
        }
示例#4
0
        public PageListClient <CommentClient> GetPageComments(Guid topicId, int pageNumber, int pageSize)
        {
            if (topicId == Guid.Empty)
            {
                return(null);
            }
            Expression <Func <ContentComment, bool> > predicate = x => x.TopicId == topicId && !x.IsHidden && !x.IsSpam;
            var comments = _commentWork.Paging(pageNumber, pageSize, "CreateTime desc", predicate);

            PageListClient <CommentClient> pageComments = new PageListClient <CommentClient>(comments, comments.Count);

            pageComments.Models = new List <CommentClient>();
            foreach (var comment in comments)
            {
                pageComments.Add(_commentDriver.ToClient(comment, excludeProperties: new string[] { "Tags" }));
            }

            return(pageComments);
        }
        public ActionResult Thread(string key, int?page)
        {
            var currentThread = string.IsNullOrEmpty(key) ? _threadDriver.RootThread : _threadDriver.GetThreadByKey(key);

            if (currentThread == null)
            {
                return(HttpNotFound());
            }

            var tagCategoryMaps           = _threadDriver.GetTagCategories(currentThread.Id);
            List <TagListClient> tagLists = new List <TagListClient>();

            foreach (var map in tagCategoryMaps)
            {
                var tagList = _tagDriver.GetTagsByCategory(map.TagCategory.Name, map.OnlyShowHotTag, map.IncludeAll, map.IncludeOther);
                tagLists.Add(tagList);
            }
            ViewBag.TagLists = tagLists;


            PageTopicFilterClient topicFilter = new PageTopicFilterClient();

            topicFilter.PageNumber = GetPageNumber(page);;
            topicFilter.ThreadKey  = currentThread.Key;
            topicFilter.Sort       = " CreateTime DESC";
            PageListClient <TopicClient> pageList = _topicDriver.PagingClientTopics(DefaultSetting.TopicsPerPage, topicFilter);
            PageTopicClient pageTopic             = new PageTopicClient()
            {
                Page = pageList, Filter = topicFilter
            };

            ViewBag.CurrentThread = currentThread;

            pageTopic.Page.GenerateUniqueId();
            return(View("Thread", pageTopic));
        }