Beispiel #1
0
        private void MarkAllThreadsRead(long userId, DateTime asOfDate)
        {
            // TODO: Make Faster.
            var threads = GetAllUnreadThreads(userId);

            foreach (var thread in threads)
            {
                ThreadRead tr = this.Db.ThreadReads.Where(thr => thr.UserID == userId && thr.ThreadID == thread.ThreadID).SingleOrDefault();

                if (tr == null)
                {
                    tr = new ThreadRead
                    {
                        ThreadID = thread.ThreadID,
                        UserID   = userId,
                        DateRead = asOfDate
                    };

                    this.Db.ThreadReads.InsertOnSubmit(tr);
                }

                tr.DateRead = (tr.DateRead > asOfDate ? tr.DateRead : asOfDate);
            }

            this.Db.SubmitChanges();
        }
Beispiel #2
0
        public ActionResult ViewThread(long?id, int?page)
        {
            int pageSize = 25;

            if (!id.HasValue)
            {
                return(View("NotAvailable"));
            }

            var t = this.Forums.GetThread(id.Value);

            if (t == null || t.IsDeleted)
            {
                return(View("NotFound"));
            }

            Forum       f = t.Forum;
            ForumAccess a = this.Security.GetUserForumAccess(CurrentUser, f);

            if (!a.CanRead)
            {
                return(View("NotAuthorized"));
            }

            lock (syncRoot)
            {
                t       = this.Forums.GetThread(id.Value);
                t.Views = t.Views + 1;
                this.Db.SubmitChanges();
            }

            if (CurrentUser != null)
            {
                ThreadRead tr = (from thr in this.Db.ThreadReads
                                 where thr.ThreadID == id && thr.UserID == CurrentUser.UserID
                                 select thr).SingleOrDefault();
                if (tr == null)
                {
                    tr = new ThreadRead
                    {
                        ThreadID = t.ThreadID,
                        UserID   = CurrentUser.UserID,
                        DateRead = DateTime.UtcNow,
                    };

                    this.Db.ThreadReads.InsertOnSubmit(tr);
                }
                else
                {
                    tr.DateRead = DateTime.UtcNow;
                }
                this.Db.SubmitChanges();
            }

            var posts     = this.GetPostsInformation(t);
            int postCount = posts.Count();
            int pages     = Pager.PageCount(postCount, pageSize);

            page = Pager.ClampPage(page, pages);

            posts = posts.OrderBy(p => p.Post.CreateDate).Skip((page.Value - 1) * pageSize).Take(pageSize);

            ForumThreadModel tm = new ForumThreadModel
            {
                Thread     = t,
                Posts      = posts.ToList(),
                UserAccess = a,
                PageInfo   = new PaginationInformation
                {
                    Pager          = this.Skins.GetDefaultThreadPager(),
                    CurrentPage    = page,
                    Items          = postCount,
                    ItemsPerPage   = pageSize,
                    ControllerName = "Forums",
                    ActionName     = "ViewThread",
                    PageAttribute  = "page",
                    RouteValues    = new System.Web.Routing.RouteValueDictionary(new { id = id })
                }
            };

            return(View("ViewThread", tm));
        }