コード例 #1
0
ファイル: FeedRecord.cs プロジェクト: arbium/democratia2
        public void PackMailRecord()
        {
            var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.Id == _userId);

            if (user == null)
            {
                return;
            }

            var groupfeed = (from _group in user.SubscriptionGroups
                             join content in DataService.PerThread.ContentSet on _group.Id equals content.GroupId
                             where content.State == (byte)ContentState.Approved && _beginDate <= content.PublishDate && content.PublishDate < _endDate && !user.BlackList.Contains(content.Author)
                             where user.Id != content.AuthorId
                             select content).ToList();
            var userfeed = (from _user in user.SubscriptionUsers
                            join content in DataService.PerThread.ContentSet on _user.Id equals content.AuthorId
                            where content.State == (byte)ContentState.Approved && _beginDate <= content.PublishDate && content.PublishDate < _endDate
                            where user.Id != content.AuthorId
                            select content).ToList();

            var feed = groupfeed.Union(userfeed).Distinct().Where(x => x.PublishDate.HasValue).OrderBy(x => x.GroupId).ThenByDescending(c => c.PublishDate);

            _content.AddRange(feed.Select(x => new SubscriptionContent(x)));

            Groups = _content.Select(x => new GroupSchema {
                Name = x.GroupName, Url = x.GroupUrl
            }).Distinct().OrderBy(x => x.Name).ToList();

            var messages = user.InboxMessages.Where(m => !m.IsRead && !m.IsDeletedByRecipient && _beginDate <= m.Date && m.Date < _endDate).ToList();

            CommentNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.CommentNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            GroupMemberNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.GroupMemberNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            GroupModeratorNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.GroupModeratorNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            PollNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.PollNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            SurveyNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.SurveyNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            ElectionNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.ElectionNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            PetitionNotices.AddRange(messages.Where(m => m.Type == (byte)MessageType.PetitionNotice).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            SystemMessages.AddRange(messages.Where(m => m.Type == (byte)MessageType.SystemMessage).Select(x => new MessageUpdate(x)).OrderByDescending(x => x.Date));
            PrivateMessages.AddRange(messages.Where(m => m.Type == (byte)MessageType.PrivateMessage).Select(x => new PrivateMessageUpdate(x)).OrderByDescending(x => x.Date));
        }