예제 #1
0
        void ThreadInfoModelFromThread(ForumRespository db, Forum_User User, IEnumerable<Forum_Thread> Threads, ICollection<ThreadInfoViewModel> InfoCollection)
        {
            foreach (var Thread in Threads)
            {
                ThreadInfoViewModel NewThreadInfo = new ThreadInfoViewModel()
                {
                    ThreadTitle = Thread.Title,
                    ThreadID = Thread.ThreadID,
                    PostCount = Thread.Posts
                };

                InfoCollection.Add(NewThreadInfo);

                if (User == null)
                    NewThreadInfo.LastViewedPost = Thread.Posts;
                else
                    NewThreadInfo.LastViewedPost = db.GetLastPost(Thread, User);

                NewThreadInfo.Locked = Thread.Locked;

                NewThreadInfo.PageCount = (Thread.Posts - 1) / POSTS_PER_PAGE + 1;
                NewThreadInfo.LastViewedPostPage = NewThreadInfo.LastViewedPost / POSTS_PER_PAGE + 1;
                NewThreadInfo.LastViewedPostID = NewThreadInfo.LastViewedPost % POSTS_PER_PAGE + 1;

                Forum_Post LastPost = Thread.Forum_Posts.Last();
                NewThreadInfo.LastPoster = new UserViewModel();
                NewThreadInfo.LastPoster.Name = LastPost.Forum_User.Username;
                NewThreadInfo.LastPoster.UserID = LastPost.Forum_User.UserID;
                NewThreadInfo.LastPostTime = LastPost.TimeStamp;
            }
        }