예제 #1
0
        public PartialFindResult <DiscussionTopicContract> GetTopics(
            int?folderId = null,
            int start    = 0, int maxResults = DefaultMax, bool getTotalCount = false,
            DiscussionTopicSortRule sort         = DiscussionTopicSortRule.DateCreated,
            DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None)
        {
            return(HandleQuery(ctx =>
            {
                var query = ctx.OfType <DiscussionTopic>()
                            .Query()
                            .WhereNotDeleted()
                            .WhereIsInFolder(folderId);

                var topics = query
                             .OrderBy(sort)
                             .Paged(new PagingProperties(start, maxResults, getTotalCount))
                             .ToArray()
                             .Select(f => new DiscussionTopicContract(f, _userIconFactory, fields))
                             .ToArray();

                var count = (getTotalCount ? query.Count() : 0);

                return PartialFindResult.Create(topics, count);
            }));
        }
예제 #2
0
 public DiscussionTopicContract GetTopic(int topicId,
                                         DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None)
 {
     return(HandleQuery(ctx => {
         return new DiscussionTopicContract(ctx.OfType <DiscussionTopic>().Load(topicId), userIconFactory, fields);
     }));
 }
예제 #3
0
        public IEnumerable <DiscussionTopicContract> GetTopicsForFolder(int folderId,
                                                                        DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None)
        {
            return(HandleQuery(ctx => {
                var folder = ctx.Load(folderId);

                return folder.Topics
                .Select(t => new DiscussionTopicContract(t, userIconFactory, fields))
                .OrderByDescending(t => t.LastComment != null ? t.LastComment.Created : t.Created)
                .ToArray();
            }));
        }
예제 #4
0
 public DiscussionTopicContract GetTopic(int topicId,
                                         DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None) => _queries.GetTopic(topicId, fields);
예제 #5
0
 public IEnumerable <DiscussionTopicContract> GetTopicsForFolder(int folderId,
                                                                 DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None) => _queries.GetTopicsForFolder(folderId, fields);
예제 #6
0
 public PartialFindResult <DiscussionTopicContract> GetTopics(
     int?folderId = null,
     int start    = 0, int maxResults = DefaultMax, bool getTotalCount = false,
     DiscussionTopicSortRule sort         = DiscussionTopicSortRule.DateCreated,
     DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None) => _queries.GetTopics(folderId, start, maxResults, getTotalCount, sort, fields);
예제 #7
0
        public DiscussionTopicContract(DiscussionTopic topic, IUserIconFactory userIconFactory, DiscussionTopicOptionalFields fields)
        {
            ParamIs.NotNull(() => topic);

            Author   = new UserWithIconContract(topic.Author, userIconFactory);
            Created  = topic.Created;
            FolderId = topic.Folder.Id;
            Id       = topic.Id;
            Name     = topic.Name;

            if (fields.HasFlag(DiscussionTopicOptionalFields.Comments))
            {
                Comments = topic.Comments.Select(c => new CommentForApiContract(c, userIconFactory)).ToArray();
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.CommentCount))
            {
                CommentCount = topic.Comments.Count;
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.Content))
            {
                Content = topic.Content;
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.LastComment) && topic.Comments.Any())
            {
                LastComment = new CommentForApiContract(topic.Comments.MaxItem(c => c.Created),
                                                        userIconFactory, includeMessage: false);
            }
        }